JSPM

graphile-utils

4.0.0-rc.11
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 86279
  • Score
    100M100P100Q164140F
  • License MIT

Utilities to help with building graphile-build plugins

Package Exports

  • graphile-utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphile-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

graphile-utils

This package contains helpers for building plugins for Graphile-Build based GraphQL schemas, such as the one in PostGraphile.

Documentation is currently available here.

PRs to improve documentation are always welcome!

Typical usage:

const {
  makeExtendSchemaPlugin,
  gql,
} = require('graphile-utils');

const MySchemaExtensionPlugin =
  makeExtendSchemaPlugin(
    build => ({
      typeDefs: gql`...`,
      resolvers: ...
    })
  );

module.exports = MySchemaExtensionPlugin;

e.g.:

makeExtendSchemaPlugin(build => ({
  typeDefs: gql`
    type Random {
      float: Float!
      number(min: Int!, max: Int!): Int!
    }
    extend type Query {
      random: Random
    }
  `,
  resolvers: {
    Query: {
      random() {
        return {};
      },
    },
    Random: {
      float() {
        return Math.random();
      },
      number(_parent, { min, max }) {
        return min + Math.floor(Math.random() * (max - min + 1));
      },
    },
  },
}));