Closed geirman closed 6 years ago
Cool. I didn't know graphql-yoga
so I'll definitely check that one out @geirman . I'll have a look at all this during the weekend. Thank you heaps for that awesome feedback. This is super useful.
Here's how to use this package with the current version of graphql-yoga :
const { GraphQLServer } = require('graphql-yoga');
const { graphqls2s } = require('graphql-s2s');
const glue = require('schemaglue');
// Schemaglue is optional, of course
const { schema, resolver } = glue('src/graphql');
const server = new GraphQLServer({
typeDefs: graphqls2s.transpileSchema(schema),
resolvers: resolver,
});
const options = {
port: process.env.PORT || 3000,
endpoint: '/graphql',
subscriptions: '/subscriptions',
playground: '/playground',
}
server.start(options, ({ port }) =>
console.log(
`Graphql server running on port ${port}!`,
),
);
No further editing of the graphql-yoga package is therefore necessary anymore, so I'm closing this issue. Feel free to comment if you still run into issues.
It's not super popular (yet), but it is a graph.cool open source project, so I'd expect it to pick up steam. It basically bundles several packages together to give you a reasonable default setup, making it easy to get started with. But I had to monkey patch them in order to get your library to play nicely with them.
Then you'll have to monkey patch the
graphql-yoga
server in the following way so thatgraphql-s2s
will work. NOTE: This wouldn't be necessary if I went with straight GraphQL-js.File: https://github.com/graphcool/graphql-yoga/blob/master/src/index.ts#L13
Then wrap
typeDefs
with the transpileSchema fn https://github.com/graphcool/graphql-yoga/blob/master/src/index.ts#L48I tried transpiling typeDevs before sending it to yoga's GraphQLServer, but I got an error saying typeDefs must be an executableSchema.
NOTE: I had to import
transpileSchema
a bit differently than your example in the docs becauseconst { transpileSchema } = graphqls2s
did not destructure properly and gave me "transpileSchema is not a function" errors.