schema field in applyGraphQL
Is there going to be a schema field for generated schema using "new GraphQLSchema(<GraphqlType>)"?
No, I'm using the makeExecutableSchema for generating the schemas. This's part of graphql-tools
I'll like to say you have done an awesome work. I'm a bit new to GraphQL and I wanted to know what if you already had a generated schema and you would want to use the schema?
{
path = "/graphql",
schema
typeDefs,
resolvers,
...
}
you could make a check if a schema field is passed as an argument like typeDefs and resolvers and skip the makeExecutableSchema, this will help those who already have their generated schemas use the endpoint.
if(!schema){
schema = makeExecutableSchema({ typeDefs, resolvers });
}
const result = await (graphql as any)(
schema,
...
);
Thanks so much
sorry I could not fully understand the generated schemas meaning. can you share with me a sample of the generated schemas and how you use it?
const { graphql, GraphQLSchema, GraphQLObjectType, GraphQLString } = 'https://raw.githubusercontent.com/adelsz/graphql-deno/v15.0.0/mod.ts'
const schema = new GraphQLSchema({
Query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
hello: {
type: GraphQLString,
resolve: () => 'Hello world!'
}
})
})
});
graphql(schema, '{ hello }').then((response) => {
console.log(response);
});
I see it. This is the wrong behavior of using this oak-graphql. If you want to use already generated schemas and resolvers, you should not use this project. makeExecutableSchema is a validator and it's checking the types and resolvers types are matching for verifying the server will be working fine. And, this is the why I use the graphql-tag and graphql-tools library.
if you're going to use that generated schemes, just use exactly same as you given to me for starting the graphql server.
here is a code example when you apply it to the middleware.
app.use(async ctx => {
if (ctx.request.hasBody) {
const body = await ctx.request.body();
const { query, variables, operationName } = body.value;
const result = await graphql(
schema,
query,
resolvers,
undefined, // or send the context
variables,
operationName,
);
ctx.response.body = result;
}
})
Thanks very much, bro you are a lifesaver 😄.