Graphql 在解析自定义标量类型时,了解值是定义为Nullable还是NotNullable
我正在创建自定义标量类型,以覆盖内置的Graphql 在解析自定义标量类型时,了解值是定义为Nullable还是NotNullable,graphql,graphql-js,transit,sanctuary,Graphql,Graphql Js,Transit,Sanctuary,我正在创建自定义标量类型,以覆盖内置的Int和Float。我想知道模式是否将该值定义为可空。我想以不同于Int的方式解析Int在我的自定义标量类型中 我想做的是在自定义标量类型的解析程序中,知道该值在模式中是否定义为可空,以便以不同的方式解析它们并抛出自定义错误 const resolvers = { // ... Int: new GraphQL.GraphQLScalarType ({ name: 'Int', description: 'Custom Int typ
Int
和Float
。我想知道模式是否将该值定义为可空。我想以不同于Int的方式解析Int代码>在我的自定义标量类型中
我想做的是在自定义标量类型的解析程序中,知道该值在模式中是否定义为可空,以便以不同的方式解析它们并抛出自定义错误
const resolvers = {
// ...
Int: new GraphQL.GraphQLScalarType ({
name: 'Int',
description: 'Custom Int type',
serialize (val, isNullable) {
},
parseValue (val, isNullable) {
// assume this parses the value
const value = transit.read (val);
// this does some type checking (using a library called sanctuary)
if (S.is ($.Integer) (value)) {
// if Nullable we want to return a maybe type
if (isNullable) return S.Just (value);
return value;
}
return isNullable ? S.Nothing : new Error ();
},
parseLiteral (ast) {
},
}),
}
Int
(可为null)的结果将是类型可能是整数
,而Int的结果代码>(不可为空)的类型应为Integer
您是否试图将42::Integer
与42::可为空的Integer
区分开来?换句话说,是否要从值推断类型?是否尝试将42::Integer
与42::Nullable Integer
区分开来?换句话说,您想从值推断类型吗?