简体   繁体   English

GraphQL 突变的输入类型声明

[英]GraphQL Input type declaration for Mutation

I'm new to GraphQL and after some coding I bumped into a problem with declaring an Input type for a Mutation.我是 GraphQL 的新手,经过一些编码后,我遇到了为 Mutation 声明输入类型的问题。 Here's my Schema:这是我的架构:

type Test {
  id: ID!
  label: String!
}

extend type Query {
  test(id : ID!): Test
  listTests (where: myWhereCondition, orderBy: myOrderByCondition): [Test!]!
}

extend type Mutation {
  createTest(label: String!, testTypes: TestTypesInput): Test!
}

input TestTypesInput {
  testTypes: [IdInput]
}

input IdInput {
  id: ID!
}

When I run my app, I get the error当我运行我的应用程序时,出现错误

Caused by: graphql.kickstart.tools.SchemaError: Expected type 'IdInput' to be a GraphQLInputType, but it wasn't, Was a type only permitted for object types incorrectly used as an input type? Caused by: graphql.kickstart.tools.SchemaError: Expected type 'IdInput' to be a GraphQLInputType, but it wasn't, Was a type only permitted for object 类型错误地用作输入类型? or vice-versa.或相反亦然。 at graphql.kickstart.tools.SchemaParser.determineType(SchemaParser:kt.400) ~[graphql-java-tools-11.0.1:jar.na] at graphql.kickstart.tools.SchemaParser.determineInputType(SchemaParser:kt.417) ~[graphql-java-tools-11.0.1:jar.na] at graphql.kickstart.tools.SchemaParser.determineInputType(SchemaParser:kt.410) ~[graphql-java-tools-11.0.1:jar.na] at graphql.kickstart.tools.SchemaParser.createInputObject(SchemaParser:kt.179) ~[graphql-java-tools-11.0.1:jar.na] at graphql.kickstart.tools.SchemaParser.parseSchemaObjects(SchemaParser:kt.79) ~[graphql-java-tools-11.0.1:jar.na] at graphql.kickstart.tools.SchemaParser.makeExecutableSchema(SchemaParser:kt.112) ~[graphql-java-tools-11.0.1:jar.na] at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration.graphQLSchema(GraphQLJavaToolsAutoConfiguration:java.143) ~[graphql-kickstart-spring-boot-autoconfigure-tools-11.1.0:j在 graphql.kickstart.tools.SchemaParser.determineType(SchemaParser:kt.400) ~[graphql-java-tools-11.0.1:jar.na] 在 graphql.kickstart.tools.SchemaParser.determinePaper4rs(SchemaParser.determinePaper4rs) ~[graphql-java-tools-11.0.1:jar.na] 在 graphql.kickstart.tools.SchemaParser.determineInputType(SchemaParser:kt.410)~[graphql-java-tools-11.0.1:jar.na] 在graphql.kickstart.tools.SchemaParser.createInputObject(SchemaParser:kt.179)~[graphql-java-tools-11.0.1:jar.na] 在 graphql.kickstart.tools.SchemaParser.parseSchemaObjects)~[graphql-java-tools-11.0.1:jar.na] [graphql-java-tools-11.0.1:jar.na] 在 graphql.kickstart.tools.SchemaParser.makeExecutableSchema(SchemaParser:kt.112) ~[graphql-java-tools-11.0.1:jar8184] 在 486067 .kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration.graphQLSchema(GraphQLJavaToolsAutoConfiguration:java.143)~[graphql-kickstart-spring-boot-autoconfigure-tools-11.1.0:j ar:na] ar:na]

I can't understand what I'm missing, to me the "IdInput" is well declared as input and reading some other examples it looks correct to me, but it clearly isn't.我不明白我错过了什么,对我来说,“IdInput”被很好地声明为input并阅读了一些其他示例,它对我来说看起来是正确的,但显然不是。 I tried to declare che IdInput as type insted of input , but it obviously doesn't work.我试图将 che IdInput 声明为inputtype ,但它显然不起作用。 How can I pass a list of input objects into an input array?如何将输入对象列表传递到输入数组中? If you need more informations I'll add them, at the moment I'm just mixing some declaration to come up with the correct one, with no success.如果您需要更多信息,我会添加它们,目前我只是混合一些声明以提出正确的声明,但没有成功。 Thank you in advance for your help!预先感谢您的帮助!

Find out this was a misleading error, since the GraphQL schema couldn't fetch with the Mutation Resolver's signature method.发现这是一个误导性错误,因为 GraphQL 模式无法使用 Mutation Resolver 的签名方法获取。 Instead of pointing out that part, it kept to break in the GraphQL Schema declaration.它没有指出那部分,而是在 GraphQL 架构声明中不断中断。 Once declared the signature method accordingly to the Schema, everything worked out like a charm.一旦根据 Schema 声明了签名方法,一切都会顺利进行。 Hope it may help someone with this misleading error handling.希望它可以帮助某人处理这种误导性的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM