Skip to content

Commit

Permalink
feat(gatsby): Allow field extensions to register return types (#16484)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprobst authored and sidharthachatterjee committed Aug 9, 2019
1 parent 4032012 commit 0df297b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/gatsby/src/schema/extensions/index.js
Expand Up @@ -10,10 +10,11 @@ const { link, fileByPath } = require(`../resolvers`)
const { getDateResolver } = require(`../types/date`)

import type { GraphQLFieldConfigArgumentMap, GraphQLFieldConfig } from "graphql"
import type { ComposeFieldConfig } from "graphql-compose"
import type { ComposeFieldConfig, ComposeOutputType } from "graphql-compose"

export interface GraphQLFieldExtensionDefinition {
name: string;
type?: ComposeOutputType;
args?: GraphQLFieldConfigArgumentMap;
extend(
args: GraphQLFieldConfigArgumentMap,
Expand Down Expand Up @@ -174,7 +175,11 @@ const toDirectives = ({
}) =>
Object.keys(extensions).map(name => {
const extension = extensions[name]
const { args, description, locations } = extension
const { args, description, locations, type } = extension
// Allow field extensions to register a return type
if (type) {
schemaComposer.createTC(type)
}
// Support the `graphql-compose` style of directly providing the field type as string
const normalizedArgs = schemaComposer.typeMapper.convertArgConfigMap(args)
return new GraphQLDirective({
Expand Down

0 comments on commit 0df297b

Please sign in to comment.