graphql-directive-uid
Unique id
directive for GraphQL schema.
The problem
Generating unique id
for each graphql schema type may be a daunting task.
This solution
The @uid
is a GraphQL directive allowing users to generate unique IDs for their queries. All benefits of GraphQL cache with minimum effort.
Table of Contents
Installation
This module is distributed via npm which is bundled with node and
should be installed as one of your project's devDependencies
:
use npm:
npm install --save graphql-directive-uid
or yarn :
yarn add graphql-directive-uid
This library has a peerDependencies
listing for:
graphql
graphql-tools
Usage
;;;; typeDefs resolvers schemaDirectives: uid: graphqlDirectiveUid // the name of directive can be as you like ;
GraphQL schema:
type Person @uid(from: ["personId", "name"]) { personId: Int name: String} type Query { persons: [Person]}
GraphQL query:
query getPersons { persons { uid personId name }}
Examples
You'll find examples of how to use it in the test directory.
Feel free to contribute more!
LICENSE
MIT