- Notifications
You must be signed in to change notification settings - Fork2
A plugin for Apollo Server that allows for adding metadata to GraphQL Introspection Query responses.
License
anvilco/apollo-server-plugin-introspection-metadata
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A plugin for Apollo Server that allows for adding metadata to GraphQL Introspection Query responses.
Using npm:
npm install --save-prod @anvilco/apollo-server-plugin-introspection-metadata
Using yarn:
yarn add @anvilco/apollo-server-plugin-introspection-metadata
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:{...}}]}]},//...]}}}
This is what you most likely came here for. See Javadoc inindex.js for more details.
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
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.
A Javascript RegEx that can be used to test a query string to determine if it's an Introspection Query or not.
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.