@graphql-ez/plugin-schema
TypeScript icon, indicating that this package has built-in type declarations

0.9.1 • Public • Published

@graphql-ez/plugin-schema

Integration with @graphql-tools/schema

It can combine with other EZ Plugins like GraphQL Scalars and GraphQL Codegen.

Usage

registerTypeDefs and registerResolvers

You can use extra helpers that this plugin adds to your builder:

These helpers are specially useful when your API deals with a big amount of different type definitions and resolvers present in a lot of different directories, since you could simply call these functions, and you will only need to import them before calling buildApp(...), and this plugin will greatly simplify your code.

import { ezSchema } from '@graphql-ez/plugin-schema';

export const { registerTypeDefs, registerResolvers, buildApp, gql } = CreateApp({
  // ...
  ez: {
    plugins: [
      //...
      ezSchema(),
    ],
  },
});

// ...

registerTypeDefs(gql`
  type Query {
    hello: String!
  }
`);

registerResolvers({
  Query: {
    hello() {
      return 'Hello World!';
    },
  },
});

// ...

buildApp();

EZSchema

You can also define an EZSchema which has all the types to make an executable schema.

import { ezSchema, EZSchema, gql } from '@graphql-ez/plugin-schema';

const schema: EZSchema = {
  typeDefs: gql`
    type Query {
      hello: String!
    }
  `,
  resolvers: {
    Query: {
      hello(_root, _args, ctx) {
        return 'world';
      },
    },
  },
};

CreateApp({
  // ...
  ez: {
    plugins: [
      // ...
      ezSchema({
        schema,
      }),
    ],
  },
});

Multiple schemas

You can specify multiple schemas, and it will automatically merge the schemas.

CreateApp({
  // ...
  schema: [schema1, schema2, schema3],
});

You can customize the merging behavior following the documentation options

ezSchema({
  // ...
  schema: [schema1, schema2, schema3],

  // Check https://www.graphql-tools.com/docs/schema-merging
  mergeSchemasConfig: {
    // ...
  },
});

Readme

Keywords

none

Package Sidebar

Install

npm i @graphql-ez/plugin-schema

Weekly Downloads

2,069

Version

0.9.1

License

MIT

Unpacked Size

20.5 kB

Total Files

6

Last publish

Collaborators

  • pablosz