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 linkbelow.
Public methods static
setup(schemas, container)— Returns a middleware ready to be mounted into the server instance. Givenschemasare expected to be an array of*.gqlfiles andcontaineris 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.