GraphQL ✎
This extension lets you serve an API endpoint made out of your schemas and resolvers.
// register extension
Grown.use(require('@grown/graphql'));
fixture`./example.gql
type Mutation { noop: Int }
type Query { truth: Int }
`;
fixture`./resolvers/Test/Query/truth/index.js
module.exports = function () {
return 42;
};
`;
// mount our GraphQL API
server.mount('/', Grown.GraphQL
.setup([__dirname + '/example.gql'],
Grown.load(__dirname + '/resolvers')));
Click ▷ RUN above and then ask with your GraphQL client:
query { truth }
— or try requesting throughthis link
below.
Public methods static
setup(schemas, container)
— Returns a middleware ready to be mounted into the server instance. Givenschemas
are expected to be an array of*.gql
files andcontainer
is the implementation.
Private* methods static
_startGraphQLServer(typeDefs, resolvers)
— Used bysetup()
to build the GraphQL middleware._bindGraphQLServer(schemas, container)
— Used bysetup()
to decorate the given resolvers.