graphql-directive-computed-property
Introduction
The directive allows creating a computed property from fields where is defined.
Table of Contents
Installation
yarn add graphql-directive-computed-property
This package requires graphql and graphql-tools as peer dependency
Usage
const makeExecutableSchema = ;const computedDirective = ; const typeDefs = ` type User { firstName: String lastName: String fullName: String @computed(value: "$firstName $lastName") } type Query { me: User }`; const resolvers = Query: firstName: 'John' lastName: 'Doe' ; moduleexports = ;
Query:
query { me { fullName }}
Result:
fullName: 'John Doe'
@rest:
Computed property work well with other directives likeExample:
admin: String @rest(url: "${URL_TO_API}") @computed(value: "Are you admin? $admin")
Directive Parameters
Directive params:
value
: String
The calculated value. It can contain other fields from the type in which it is defined.
Example:
@computed(value: "$firstName $lastName")
@computed(value: "$price $")
Contributing
I would love to see your contribution. ❤️
For local development (and testing), all you have to do is to run yarn
and then yarn dev
. This will start the Apollo server and you are ready to contribute 🎉
Run yarn test (try --watch
flag) for unit tests (we are using Jest)
LICENSE
The MIT License (MIT) 2018 - Luke Czyszczonik - mailto:lukasz.czyszczonik@gmail.com