@theconcurrent/query-generator
v0.0.33
Published
GraphQL Code Generator plugin for generating operation queries based on resources.
Downloads
17
Maintainers
Readme
@theconcurrent/query-generator
Table of Contents
Introduction
@theconcurrent/query-generator
is an innovative GraphQL Code Generator plugin designed for both low-code and no-code environments. It's a powerful GraphQL tool that automates the process of query generation from your GraphQL schema. With @theconcurrent/query-generator, you can generate GraphQL queries automatically, making GraphQL development much more efficient and error-free.
It's perfect for any development process from low-code to no-code scenarios. Embrace the trend of automated query generation and make your development process more efficient with @theconcurrent/query-generator. Experience the ease of use that comes with a tool that fits seamlessly into your GraphQL automation tools kit. Make your project more visible and approachable for developers of all levels of experience, from no-code enthusiasts to seasoned professionals. Try @theconcurrent/query-generator
today!
Why should you use @theconcurrent/query-generator?
Automate Query Generation Writing queries manually based on your GraphQL schema can be a time-consuming task. However, using this plugin, you can greatly reduce the effort required.
Prevent Errors When writing queries manually, mistakes such as using incorrect field names or writing queries that do not match the schema are common. This plugin generates queries based on your schema, thus preventing such errors.
Ease of Maintenance When your schema changes, you need to update all related queries. But with this plugin, you can resolve this issue by simply generating new query documents.
If you want to utilize cutting-edge technology for efficient development, try @theconcurrent/query-generator. It may be the step to elevate your project to a new level.
Getting Started
To install @theconcurrent/query-generator
, you need to have the GraphQL Code Generator installed first.
yarn add -d @graphql-codegen/cli
yarn add -d @theconcurrent/query-generator
Next, create a codegen.yml file to configure your GraphQL Code Generator. This file specifies your GraphQL schema file, the output file for the generated queries, and the plugins you want to use:
# codegen.yml
schema:
- ./schema.graphql
generates:
queries.graphql:
plugins:
- '@theconcurrent/query-generator'
config:
concurrent: ./config.json
You'll also need a config.json file that contains configuration details for the @theconcurrent framework. This includes the paths to the different GraphQL resources you want to query:
// config.json
{
"adminPath": "admin",
"resources": [
{
"name": "User",
"list": { "path": "admin.userList" },
"show": { "path": "admin.user" },
"create": { "path": "userCreate.user" },
"update": { "path": "userUpdate.user" },
"delete": { "path": "userDelete.user" }
}
],
"nodeRepresentatives": ["id"],
"collection": {
"dataPath": "nodes",
"totalPath": "totalCount",
"typeNameSuffix": "Collection"
}
}
Now, let's create a GraphQL schema file. This file defines the shape of your data:
# schema.graphql
type Query {
admin: Admin
}
type Admin {
user(id: ID): User
userList: UserCollection!
}
type User {
id: ID
name: String
}
type UserCollection {
nodes: [User!]
totalCount: Int
}
input UserCreateInput {
userInput: UserInput!
clientMutationId: String
}
input UserInput {
name: String
}
type UserCreatePayload {
user: User!
clientMutationId: String
}
type UserDeletePayload {
user: User!
clientMutationId: String
}
input UserDeleteInput {
clientMutationId: String
id: ID!
}
type UserUpdatePayload {
user: User!
clientMutationId: String
}
input UserUpdateInput {
userInput: UserInput!
clientMutationId: String
id: ID!
}
type Mutation {
userCreate(input: UserCreateInput!): UserCreatePayload
userDelete(input: UserDeleteInput!): UserDeletePayload
userUpdate(input: UserUpdateInput!): UserUpdatePayload
}
Once you've set up everything, you can run the GraphQL Code Generator. The output will be a file called queries.graphql containing the generated queries:
yarn graphql-codegen
# queries.graphql
query userList {
admin {
userList {
nodes {
id
name
}
totalCount
}
}
}
query user($id: ID) {
admin {
user(id: $id) {
id
name
}
}
}
mutation userCreate($input: UserCreateInput!) {
userCreate(input: $input) {
user {
id
name
}
}
}
mutation userUpdate($input: UserUpdateInput!) {
userUpdate(input: $input) {
user {
id
name
}
}
}
mutation userDelete($input: UserDeleteInput!) {
userDelete(input: $input) {
user {
id
name
}
}
}