poetic / apollo-datasource-graphql

GraphQL/Apollo DataSource to connect to GraphQL API's from your Apollo Server
84 stars 18 forks source link

Proposal to change the API #4

Open ThisIsMissEm opened 6 years ago

ThisIsMissEm commented 6 years ago

Currently the GraphQLDataSource package kind of follows RESTDataSource, but also uses ApolloLink infrastructure. It'd be great to have this basically like using ApolloClient, e.g.

class MyApi extends GraphQLDataSource {
  constructor() {
    this.link = ApolloLink.from([
      onError,
      createHttpLink({
        fetch,
        uri: "https://swapi/graphql"
      })
    ])

    super();
  }

  fetchStarships(type) {
    return this.query(gql`...`, ...);
  }
}

This would allow custom error handling, usage of batching, retries, etc.

This commit also adds some missing types and raises several questions.

kmills006 commented 5 years ago

@ThisIsMissEm - Hey! Thank you for this, I apologize for the delay. I will review your proposed changes this week, at first glance I'm super stoked to see what you have done!

hkjorgensen commented 5 years ago

@ThisIsMissEm @kmills006 can we make this happen? This is the first/only graphql datasource for ApolloServer - would love to contribute to this instead of rolling my own DataSource.

I think the proposed changes are great and would love to see them merged. Then add resolveURL() and some tests. It all depends on if this PR get's merged.

ThisIsMissEm commented 5 years ago

Hi! I'm no longer using this in a work context, so I'm not sure when I'll get time to loopback around and update it. Feel free to make changes.

Emelia

On 21. Dec 2018, at 15:15, Henrik Kok Jørgensen notifications@github.com wrote:

@hkjorgensen commented on this pull request.

In src/GraphQLDataSource.ts:

}

Should be renamed to resolveURL

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

yaacovCR commented 5 years ago

Novice programmer here, made a package to use datasource pattern for graphql endpoints with Apollo Client cache for stitching, would love comments/suggestions on the approach, the code, whatever, etc, etc.

Documentation: https://yaacovcr.github.io/apollo-stitcher Working example: https://github.com/yaacovCR/nextjs-graphql-starter

I am not too familiar with TypeScript, much of this could probably be reoriented by those more in the know as pull requests to graphql-tools and/or this package.

Enalmada commented 5 years ago

@kmills006 These changes seem like they would really benefit the community and set the stage for more people to be able to contribute in the right direction. Given that the author isn't in a position to merge, could you finish the effort?