https://github.com/mvr-studio/graphql-codegen-plugin-schema-to-operations
GraphQL Codegen plugin for generating queries and mutations out of schema
https://github.com/mvr-studio/graphql-codegen-plugin-schema-to-operations
codegen graphql graphql-codegen plugin
Last synced: 2 months ago
JSON representation
GraphQL Codegen plugin for generating queries and mutations out of schema
- Host: GitHub
- URL: https://github.com/mvr-studio/graphql-codegen-plugin-schema-to-operations
- Owner: mvr-studio
- License: mit
- Created: 2022-03-07T09:56:44.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-08T10:31:27.000Z (about 3 years ago)
- Last Synced: 2024-03-23T22:01:58.033Z (about 1 year ago)
- Topics: codegen, graphql, graphql-codegen, plugin
- Language: TypeScript
- Homepage:
- Size: 106 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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:
```bash
$ yarn add @mvr-studio/graphql-codegen-plugin-schema-to-operations
```Add it to your codegen.yaml:
```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:
```gql
scalar Datetype 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:
```gql
query me_query {
me {
createdAt
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:
```yaml
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](https://github.com/ardatan/graphql-tools) - Thanks for the [schema processor](https://github.com/ardatan/graphql-tools/blob/master/packages/utils/src/build-operation-for-field.ts)