yarn add @graphql-ez/plugin-schema
pnpm add @graphql-ez/plugin-schema
npm install @graphql-ez/plugin-schema
Integration with @graphql-tools/schema
It can combine with other EZ Plugins like GraphQL Scalars and GraphQL Codegen.
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();
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,
}),
],
},
});
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: {
// ...
},
});
@graphql-ez/plugin-schema
MIT
0.9.0
Dec 18th, 2022