Skip to content
/ graphql-x Public

GraphQL eXpansion is a library designed to make GraphQL schema authoring less of a hassle by automating the repetitive bits using macro directives. Try it in playground linked below!

License

Notifications You must be signed in to change notification settings

c5n8/graphql-x

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL eXpansion

npm version

GraphQL eXpansion is a library designed to make GraphQL schema authoring less of a hassle by automating the repetitive bits using macro directives.

Try it in playground linked below to get a sense on how it works.

GraphQL X Playground

Quick Start

Install the package through your preferred Node.js package manager.

npm install @txe/graphql-x

Run the command

npx graphql-x \
  --schema=./path-to-initial/schema.graphql \
  --output=./path-to-expanded/schema.graphql

Available Macro Directives

directive @create on OBJECT

directive @update on OBJECT

# Exclude field as field of input type
# generated by @create or @delete.
directive @readonly on FIELD_DEFINITION

directive @delete on OBJECT

directive @item on OBJECT

directive @list(field: String!) on OBJECT

directive @relatedList on FIELD_DEFINITION

Example

Initial schema

directive @create on OBJECT

directive @readonly on FIELD_DEFINITION

scalar DateTime

type Post @create {
  id: ID!
  createdAt: DateTime @readonly
  text: String
}

Expanded schema

directive @create on OBJECT

directive @readonly on FIELD_DEFINITION

scalar DateTime

type Post @create {
  id: ID!
  createdAt: DateTime @readonly
  text: String
}

# start: @create Post

type Mutation {
  createPost(input: CreatePostInput!): CreatePostOutput!
}

input CreatePostInput {
  data: CreatePostDataInput
  dryRun: Boolean
}

input CreatePostDataInput {
  text: String
}

union CreatePostOutput
  @signature(fields: ["issues", "result"])
  @member(type: "CreatePostResult", signature: "result")
  @member(type: "CreatePostValidation", signature: "issues") =
  | CreatePostResult
  | CreatePostValidation

type CreatePostResult {
  result: Post!
}

type CreatePostValidation {
  issues: CreatePostValidationIssues!
}

scalar CreatePostValidationIssues @issues(input: "CreatePostInput")

# end: @create Post

# start: globals

directive @signature(fields: [String!]!) on UNION

directive @member(type: String!, signature: String!) repeatable on UNION

directive @issues(input: String!) on SCALAR

# end: globals

About

GraphQL eXpansion is a library designed to make GraphQL schema authoring less of a hassle by automating the repetitive bits using macro directives. Try it in playground linked below!

Resources

License

Stars

Watchers

Forks