Docs

GraphQL EZ

Get Started

Plugin Hub > Schema

npm version
yarn add @graphql-ez/plugin-schema

@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: { // ... }, });

Plugin Details

Identifier
@graphql-ez/plugin-schema
License
MIT
Version
0.9.0
Updated
Dec 18th, 2022