What is @graphql-codegen/plugin-helpers?
The @graphql-codegen/plugin-helpers package provides utility functions and types that are used to develop plugins for GraphQL Code Generator. It helps with the creation of custom plugins by providing common functionalities such as schema and document handling, plugin validation, and configuration management.
What are @graphql-codegen/plugin-helpers's main functionalities?
Validate Plugins
This feature allows developers to validate the structure of plugins to ensure they conform to the expected interface required by GraphQL Code Generator.
const { validatePlugins } = require('@graphql-codegen/plugin-helpers');
const plugins = [
{ plugin: require('some-graphql-codegen-plugin') }
];
validatePlugins(plugins);
Normalize Output Parameters
This utility normalizes output parameters, which can be used to handle file paths and names in a consistent manner across different plugins.
const { normalizeOutputParam } = require('@graphql-codegen/plugin-helpers');
const output = 'path/to/output.ts';
const normalizedOutput = normalizeOutputParam(output);
Create Schema AST
This function is used to create a GraphQL schema AST from a GraphQL schema object, which can then be used by plugins to generate code.
const { createSchemaAst } = require('@graphql-codegen/plugin-helpers');
const { buildSchema } = require('graphql');
const schema = buildSchema(`type Query { hello: String }`);
const schemaAst = createSchemaAst(schema);
Other packages similar to @graphql-codegen/plugin-helpers
graphql-tools
The graphql-tools package is a set of utilities for working with GraphQL schemas in JavaScript. It provides functionalities for schema stitching, mocking, and more. While it overlaps with some of the schema handling features of @graphql-codegen/plugin-helpers, it is more focused on schema manipulation rather than code generation plugin development.
graphql-config
graphql-config is a tool for loading GraphQL configuration files. It helps developers manage and share configurations for their GraphQL projects. While it also deals with GraphQL configurations, it is not specifically tailored for code generation plugin development like @graphql-codegen/plugin-helpers.