Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A plugin for Apollo Server that allows for adding metadata to GraphQL Introspection Query responses.

License

NotificationsYou must be signed in to change notification settings

anvilco/apollo-server-plugin-introspection-metadata

Repository files navigation

A plugin for Apollo Server that allows for adding metadata to GraphQL Introspection Query responses.

Installation

Using npm:

npm install --save-prod @anvilco/apollo-server-plugin-introspection-metadata

Using yarn:

yarn add @anvilco/apollo-server-plugin-introspection-metadata

Usage

Consider the following example GraphQL SDL:

typeMyType {myField(myArg:String  ):String}typeQuery {myQuery(myArg:String  ):String}typeMutation {myMutation(myArg:String  ):String}interfaceMyInterface {id:ID}enumMyEnum {  ONE  TWO  THREE}

When instantiatingApolloServer, pass the following options:

import{ApolloServer}=from'apollo-server'importIntrospectionMetadataPluginfrom'@anvilco/apollo-server-plugin-introspection-metadata'// All keys are optional, all the way down the object.// Only build/include what you want to add metadata for :)constschemaMetadataByKind={// Metadata for things of the kind "OBJECT"OBJECT:{MyType:{// Arbitrary metadata about the MyType Objectmetadata:{foo:"bar",baz:"bop",}fields:{myField:{// Arbitrary metadata about the myField Fieldmetadata:{...}args:{myArg:{// Arbitrary metadata about the myArg Argumentmetadata:{...}}}}}},    MyOtherType:{...},Query:{// Queries you've defined end up as Fields in the Queries Type, so this// structure follows that patternfields:{myQuery:{// Arbitrary metadata about the myQuery Querymetadata:{...}args:{myArg:{// Arbitrary metadata about the myArg Argumentmetadata:{...}}}}}},Mutation:{// Mutations you've defined end up as Fields in the Mutation Type, so// this structure follows that patternfields:{myMutation:{// Arbitrary metadata about the myMutation Mutationmetadata:{...}args:{myArg:{// Arbitrary metadata about the myArg Argumentmetadata:{...}}}}}},    ...},// Metadata for things of the kind "INPUT_OBJECT"INPUT_OBJECT:{    ...},// Metadata for things of the kind "SCALAR"SCALAR:{    ...},// Metadata for things of the kind "ENUM"ENUM:{    ...},// Metadata for things of the kind "INTERFACE"INTERFACE:{    ...},}// If you want to only add this metadata in the Development// environment:constapolloPlugins=[];if(process.env.NODE_ENV==='development'){apolloPlugins.push(IntrospectionMetadataPlugin({schemaMetadata:schemaMetadataByKind}))}constapolloServer=newApolloServer({//...introspection:true,plugins:apolloPlugins,//...})

Output of the Intropection Query will the become something like this:

{data:{__schema:{//...types:[{kind:"OBJECT"name:"MyType"metadata:{foo:"bar",baz:"bop",},fields:[{//...name:"myField",// myField metadatametadata:{...}args:[{//...name:"myArg",// myField's myArg metadatametadata:{...}}]}]},{kind:"OBJECT"name:"Query"fields:[{//...name:"myQuery",// myQuery metadatametadata:{...}args:[{//...name:"myArg",// myQuery's myArg metadatametadata:{...}}]}]},{kind:"OBJECT"name:"Mutation"fields:[{//...name:"myMutation",// myMutation metadatametadata:{...}args:[{//...name:"myArg",// myMutation's myArg metadatametadata:{...}}]}]},//...]}}}

API

generateApolloPlugin (default export)

This is what you most likely came here for. See Javadoc inindex.js for more details.

addMetadata

If you're not actually using Apollo Server, or want to augment an Introspection Query response from somewhere else with your metadata, then this function may be what you're looking for. See Javadoc inindex.js

isIntrospectionQuery

A function that takes the Apollo context as an argument and returns a Boolean indicating whether it appears to be an Introspection Query or not. Useful if you're considering implementing your owntestFn to provide to thegenerateApolloPlugin call.

REGEX_INTROSPECTION_QUERY

A Javascript RegEx that can be used to test a query string to determine if it's an Introspection Query or not.

References

Inspired from@cleartax/apollo-server-plugin-introspection-auth.

About

A plugin for Apollo Server that allows for adding metadata to GraphQL Introspection Query responses.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp