@forrestjs/service-fastify-gql (deprecated)
It exposes a GraphQL API that you can easily extend.
Apollo GraphQL Studio
Once your server is up and running, you can run the Apollo GraphQL studio:
https://studio.apollographql.com/sandbox/explorer
Just point the Sandbox target to http://localhost:8080/graphql
Extend the schema:
Add a new custom scalar type:
registerAction({
target: '$FASTIFY_GQL_EXTEND_SCHEMA',
handler: () => ({
typeDefs: gql`
scalar Age
`,
resolvers: {
Age: new GraphQLScalarType({
name: 'Age',
description: 'between 18 and 56.',
parseValue: getAge,
serialize: getAge,
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
if (!isValidAge(ast.value)) {
throw new GraphQLError('Age must be between 18 and 60');
}
return getAge(ast.value);
}
return null;
},
}),
},
}),
});
Add new fields to queries or mutations:
(Age comes from the previous extension)
registerAction({
target: '$FASTIFY_GQL_EXTEND_SCHEMA',
handler: () => ({
typeDefs: gql`
type Foo {
a: Age!
b: String!
}
extend type Query {
foo: Foo!
}
`,
resolvers: {
Query: {
foo: () => ({
a: 22,
b: 'y',
}),
},
},
}),
});