0.2.0 • Published 8 years ago
graphql-directive-uid v0.2.0
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-uidor yarn :
yarn add graphql-directive-uidThis library has a peerDependencies listing for:
graphqlgraphql-tools
Usage
import { makeExecutableSchema } from 'graphql-tools';
import graphqlDirectiveUid from 'graphql-directive-uid';
import typeDefs from './schema.graphql';
import resolvers from './resolvers';
export default makeExecutableSchema({
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