0.3.0 • Published 10 months ago

@prisma-to-graphql/graphql-codegen-operation-params v0.3.0

Weekly downloads
-
License
(MIT or CC0 1.0)
Repository
github
Last release
10 months ago

@prisma-to-graphql/graphql-codegen-operation-params

This 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.

Install

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.)

Example

The output looks like this:

import {SchemaOperationTypeNames} from '@prisma-to-graphql/core';

export const operationFields: Readonly<SchemaOperationTypeNames> = {
    Mutation: {
        myMutationResolver: {
            args: {
                where: 'User!',
                data: 'UserInput!',
            },
            output: 'Boolean!',
        },
    },
    Query: {
        getLatestUser: {
            args: {},
            output: 'User!',
        },
        findUser: {
            args: {
                id: 'String',
                settings: 'Settings',
            },
            output: 'User',
        },
    },
};

Usage

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:

    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<string> {
        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.

0.3.0

10 months ago

0.2.4

10 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago