Amazon web services graphql工具的makeExecutableSchema因模式中的AWSDateTime而失败
我正在使用graphql工具模拟来自Appsync的响应,对于将AWSDateTime作为某些字段的数据类型的模式,这是失败的。以下是我得到的错误: 未捕获错误:未知类型“AWSDateTime” 未知类型“AWSDateTime” 未知类型“AWSDateTime” 这是它失败的代码:Amazon web services graphql工具的makeExecutableSchema因模式中的AWSDateTime而失败,amazon-web-services,graphql,aws-appsync,Amazon Web Services,Graphql,Aws Appsync,我正在使用graphql工具模拟来自Appsync的响应,对于将AWSDateTime作为某些字段的数据类型的模式,这是失败的。以下是我得到的错误: 未捕获错误:未知类型“AWSDateTime” 未知类型“AWSDateTime” 未知类型“AWSDateTime” 这是它失败的代码: import { SchemaLink } from "apollo-link-schema"; import { makeExecutableSchema, addMockFunctionsToSchema
import { SchemaLink } from "apollo-link-schema";
import { makeExecutableSchema, addMockFunctionsToSchema } from "graphql-tools";
const typeDefs = `
type Dates {
createdAt: AWSDateTime
updatedAt: AWSDateTime
}
type Query {
getDates(id: ID!): Dates
}`;
const schema = makeExecutableSchema({ typeDefs });
你知道我如何解决这个问题吗?我知道AWSDateTime是专门为appsync定义的标量类型,所以它可能无法工作。但是有什么解决办法吗。使用ApolloLink客户端,它工作正常 除了5个内置标量之外,您使用的每个标量都必须在模式中明确定义。这是一个分为两步的过程: 首先,添加类型定义:
scalar AWSDateTime
其次,提供一个GraphQLScalarType对象,它封装标量的解析和序列化逻辑。使用makeExecutableSchema
,这是通过解析器映射提供的
const resolvers = {
...
AWSDateTime: new GraphQLScalarType({ ... }),
}
有关更多详细信息,请参阅。如果序列化和解析逻辑并不重要,因为这只是为了模拟,那么您可以使用现有标量的方法,比如字符串
const resolvers = {
...
AWSDateTime: new GraphQLScalarType({
name: 'AWSDateTime',
parseValue: GraphQLString.parseValue,
parseLiteral: GraphQLString.parseLiteral,
serialize: GraphQLString.serialize,
}),
}
除了5个内置标量之外,您使用的每个标量都必须在模式中显式定义。这是一个分为两步的过程: 首先,添加类型定义:
scalar AWSDateTime
其次,提供一个GraphQLScalarType对象,它封装标量的解析和序列化逻辑。使用makeExecutableSchema
,这是通过解析器映射提供的
const resolvers = {
...
AWSDateTime: new GraphQLScalarType({ ... }),
}
有关更多详细信息,请参阅。如果序列化和解析逻辑并不重要,因为这只是为了模拟,那么您可以使用现有标量的方法,比如字符串
const resolvers = {
...
AWSDateTime: new GraphQLScalarType({
name: 'AWSDateTime',
parseValue: GraphQLString.parseValue,
parseLiteral: GraphQLString.parseLiteral,
serialize: GraphQLString.serialize,
}),
}