@mvr-studio/graphql-codegen-plugin-schema-to-operations
v0.1.5
Published
Easily generate GraphQL operations for provided schema. Our motivation was to create the plugin to create operations for further processing by GraphQL Codegen (in our case to generate SWR and graphql-request SDK out of the box for basic CRUD operations).
Downloads
3
Maintainers
Readme
GraphQL Codegen Plugin Schema To Operations
Easily generate GraphQL operations for provided schema. Our motivation was to create the plugin to create operations for further processing by GraphQL Codegen (in our case to generate SWR and graphql-request SDK out of the box for basic CRUD operations).
Installation
Install the module:
$ yarn add @mvr-studio/graphql-codegen-plugin-schema-to-operations
Add it to your codegen.yaml:
generates:
operations.graphql:
schema: ./schema.graphql # or external address pointing to schema
plugins:
- '@mvr-studio/graphql-codegen-plugin-schema-to-operations'
That's it. Now you can run the codegen.
Usage
The plugin will likely transform given schema:
scalar Date
type AuthResponse {
jwt: String!
}
type Mutation {
logInUser(email: String!, password: String!): AuthResponse
}
type Query {
me: User
}
enum Role {
ADMIN
USER
}
type User {
id: String!
email: String!
name: String
role: Role
createdAt: Date!
updatedAt: Date!
}
Into following operations:
query me_query {
me {
createdAt
email
id
name
role
updatedAt
}
}
mutation logInUser_mutation($email: String!, $password: String!) {
logInUser(email: $email, password: $password) {
jwt
}
}
Additional Config
depthLimit
By default the plugin fetches fields for depthLimit=1
depth. But the property is adjustable like:
generates:
operations.graphql:
schema: ./schema.graphql # or external address pointing to schema
config:
depthLimit: 3
plugins:
- '@mvr-studio/graphql-codegen-plugin-schema-to-operations'
Credits
graphql-tools - Thanks for the schema processor