使用JSON的graphql创建无效的架构

时间:2018-11-22 03:18:25

标签: javascript node.js express graphql apollo

因此,我正在尝试启用如下定义的JSON标量类型,但是这使我抛出了无效的GraphQL模式错误。我定义错了什么?我只是想遵循他们的指南:

https://www.apollographql.com/docs/graphql-tools/scalars.html

const GraphQLJSON = require("graphql-type-json")
const {
    makeExecutableSchema
} = require("graphql-tools")

const typeDefs = `
    scalar JSON

    type Query {
        hello: String,
        print (name: String): String,
        json (a: JSON): JSON
    }
`

// Provide resolver functions for your schema fields
export const resolvers = {
    Query: {
        hello:
            function (parent, args, context)
            {
                console.log(context.body)
                return "Hello"
            },
        print:
            function (parent, args, context)
            {
                console.log(context.body)
                console.log(args)
                return "hello"
            },
        json:
            function (parent, args, context)
            {
                console.log(args)
                return args
            }
    },
    JSON: GraphQLJSON
}

export default makeExecutableSchema({
    typeDefs,
    resolvers
})

错误:

Error: Expected { resolvers: { Query: { hello: [function hello], print: [function print], json: [function json] }, JSON: JSON }, default: { astNode: undefined, extensionASTNodes: undefined, _queryType: Query, _mutationType: null, _subscriptionType: null, _directives: [@skip, @include, @deprecated], _typeMap: { Query: Query, String: String, JSON: JSON, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, Boolean: Boolean, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _implementations: {}, _possibleTypeMap: undefined, __validationErrors: undefined, __allowedLegacyNames: [] } } to be a GraphQL schema.

0 个答案:

没有答案