1.2.8 • Published 1 year ago

graphql-inherit-transformer v1.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

This is a custom GraphQL transformer for using with AWS AppSync and Amplify.

It allows you to add inheritance to types such that they can inherit all attributes from a parent type without the need for repetition of attributes

It also automatically converts any attributes for Query, Mutation and Subscription operation that are types instead of inputs

graphql-inherit-transformer

Pull requests are welcome! npm GitHub license

Installation

npm install --save graphql-inherit-transformer

How to use

Setup custom transformer

Edit amplify/backend/api/<YOUR_API>/transform.conf.json and append "graphql-inherit-transformer" to the transformers field.

"transformers": [
	"graphql-inherit-transformer"
]

Use @inherit directive

Add the @inherit(from: ["type1", "type2"]) directive to target types:

type Model {
	id: ID!
	createdAt: AWSTimestamp!
}

type UserModel @inherit(from: ["Model"]) {
	name: String!
}

After transformation results in:

type Model {
	id: ID!
	createdAt: AWSTimestamp!
}

type UserModel {
	name: String!
	id: ID!
	createdAt: AWSTimestamp!
}

Automatic input conversion

type Model {
	id: ID!
	createdAt: AWSTimestamp!
}

type Mutation {
	createModel(model: Model) Model
}

After transformation results in:

type Model {
	id: ID!
	createdAt: AWSTimestamp!
}

type ModelInput {
	id: ID!
	createdAt: AWSTimestamp!
}

type Mutation {
	createModel(model: ModelInput) Model
}

License

The MIT License

Credits

Created by James at Next Door Tutor Ltd

Used the graphql-ttl-transformer package by Florian Gyger Software as an example template to get started as I had no experience of custom graphQL transformers and had previously used this package.