Socket
Book a DemoInstallSign in
Socket

graphql-directive-uid

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-directive-uid

Graphql direvtive provides uid

0.2.0
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 05 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.