This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@forrestjs/service-fastify-gql

5.0.3 • Public • Published

@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

example

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',
        }),
      },
    },
  }),
});

Dependencies (5)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @forrestjs/service-fastify-gql

    Weekly Downloads

    1

    Version

    5.0.3

    License

    MIT

    Unpacked Size

    152 kB

    Total Files

    6

    Last publish

    Collaborators

    • marcopeg