Basic Example
In the documentation you will see something like this:
import graphQL from 'graphql'; // Construct a schema using GraphQL schema language export default graphQL.buildSchema(` type Customer { dob: String } `);
Diving in further
{ "name": "Lewis Kinsella", "dob": "1994-09-02" }
However, further inspection of the docs plus also the common use case test in the code base shows that this library works differently. Instead of using buildSchema we have "makeExecutableSchema" with some typeDefs and resolvers.
import gqlTools from 'graphql-tools';
const schema = gqlTools.makeExecutableSchema({
typeDefs,
resolvers,
});
So how do I change my existing work to fit with this?
Let's start at the end...
app.use('/graphql', graphqlHTTP({
schema
});
It looks like resolvers are no longer added as the "root value" argument in the graphqlHTTP object.
Instead we are adding the schema object only. How do we make that?
const schema = gqlTools.makeExecutableSchema({
typeDefs,
resolvers,
});
The typeDefs here is mostly what we had before except now we need to merge in our extra scalar functionality.
a) resolvers are merged with the scalar tool resolvers.
const resolvers = gqlTools.mergeResolvers([root, scalarResolvers.resolvers]);
andconst typeDefs = merge.mergeTypeDefs([customTypeDefs, ...scalarTypeDefs.typeDefs]);
import graphQL from 'graphql'; // Construct a schema using GraphQL schema language export default graphQL.buildSchema(` type Customer { dob: Date } `);
No comments:
Post a Comment