Socket
Socket
Sign inDemoInstall

graphql-directive-id

Package Overview
Dependencies
4
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    graphql-directive-id

Generate an id field from other columns.


Version published
Maintainers
1
Install size
573 kB
Created

Readme

Source

graphql-directive-id

Usage

import {createIdDirective} from 'graphql-directive-id'
import { makeExecutableSchema  } from '@graphql-tools/schema'
import { printSchemaWithDirectives } from '@graphql-tools/utils'

let schema = makeExecutableSchema({
  typeDefs: [
    idDirectiveTypeDefs,
    `
      type Query {
        people: [Person]
        locations: [Location]
      }
 
      type Person @id(from: ["personID"]) {
        personID: Int
        name: String
      }
 
      type Location @id(name: "uid", from: ["locationID"]) {
        locationID: Int
        address: String
      }
    `
  ],
  resolvers: {
    Query: {
      people: () => [
        {
          personID: 1,
          name: 'Ben'
        }
      ],
      locations: () => [
        {
          locationID: 1,
          address: '104 10th St'
        }
      ]
    }
  }
})
schema = idDirectiveTransformer(schema)

console.log(printSchemaWithDirectives(schema))

Transformed schema:

schema {
  query: Query
}

directive @id(name: String, from: [String]) on OBJECT

type Query {
  people: [Person]
  locations: [Location]
}

type Person @id(from: ["personID"]) {
  personID: Int
  name: String
  """Unique ID"""
  id: ID
}

type Location @id(name: "uid", from: ["locationID"]) {
  locationID: Int
  address: String
  """Unique ID"""
  uid: ID
}

Keywords

FAQs

Last updated on 23 Mar 2023

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc