GraphQL-Codegen plugin for storing GraphQL param names as TypeScript strings.
npm install @prisma-to-graphql/graphql-codegen-operation-paramsThis is a plugin for GraphQL-Codegen that generates a run-time const containing all Mutation and Query GraphQL resolver type names as strings.
In particular, this package is needed by @prisma-to-graphql/fetch-graphql to automatically build strictly typed GraphQL requests.
This plugin does not generate TS types for the GraphQL types encoded in the strings (use @graphql-codegen/typescript for that), it merely stores them as strings so that run-time query builders can use them.
``sh`
npm i -D @prisma-to-graphql/graphql-codegen-operation-params
npm i @prisma-to-graphql/core
(Non-dev install is recommended for @prisma-to-graphql because the generated code includes import statements from that package.)
The output looks like this:
`TypeScript
import {SchemaOperationTypeNames} from '@prisma-to-graphql/core';
export const operationFields: Readonly
Mutation: {
myMutationResolver: {
args: {
where: 'User!',
data: 'UserInput!',
},
output: 'Boolean!',
},
},
Query: {
getLatestUser: {
args: {},
output: 'User!',
},
findUser: {
args: {
id: 'String',
settings: 'Settings',
},
output: 'User',
},
},
};
`
This plugin is used internally by the prisma-to-graphql. If you are using prisma-to-graphql directly, there's no need to worry about how to install or use _this_ package (prisma-to-graphql will take care of that for you).
Otherwise, you can use this package as a plugin for any graphql-codegen execution.
- Example graphql-codegen API usage:
`TypeScript
import {codegen} from '@graphql-codegen/core';
import {Types} from '@graphql-codegen/plugin-helpers';
import {buildSchema, parse, printSchema} from 'graphql';
import * as operationParamsPlugin from '@prisma-to-graphql/graphql-codegen-operation-params';
export async function generateCodegenOutput(schemaString: string): Promise
const config: Types.GenerateOptions = {
documents: [],
config: {},
filename: '',
schema: parse(printSchema(buildSchema(schemaString))),
plugins: [
{
// this plugin needs no config
'operation-params': {},
},
],
pluginMap: {
'operation-params': operationParamsPlugin,
},
};
return await codegen(config);
}
``
Note that there is no config for this plugin.