Skip to content

Fields and Objects marked with @Private will not be exposed through the GraphQL API.

License

Notifications You must be signed in to change notification settings

Pikachews/graphql-directive-private

 
 

Repository files navigation

graphql-directive-private

Fields and Objects marked with @private will be removed from the schema. They will not appear in introspection and they will not be queryable.

Example

import { PrivateDirective, privateTransform, privateDirectiveDeclaration } from 'graphql-directive-private'
const typeDefs = `
    ${privateDirectiveDeclaration}

    type User @private {
      userId: Int
      post: Post
    }

    type Post {
      postId: Int @private
      user: User
    }

    type Query {
      user: User
      post: Post
    }
  `

const publicSchema = makeExecutableSchema({
  typeDefs,
  schemaDirectives: {
    private: PrivateDirective
  },
})
const privateSchema = transformSchema(publicSchema, [privateTransform(publicSchema)])

const query = gql`
  query {
    user {
      userId
      post {
        postId
      }
    }
    post {
      postId
      user {
        userId
      }
    }
  }
`
const response = await execute(schema, query)
// response == { data: { post: { postId: null } } }

About

Fields and Objects marked with @Private will not be exposed through the GraphQL API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • TypeScript 55.9%
  • JavaScript 44.1%