graphql-directive-uid

0.2.0 • Public • Published

graphql-directive-uid

Unique id directive for GraphQL schema.

Version downloads

PRs Welcome MIT License

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

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

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-directive-uid

Weekly Downloads

3

Version

0.2.0

License

MIT

Unpacked Size

11 kB

Total Files

17

Last publish

Collaborators

  • czystyl