Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphql 在解析自定义标量类型时,了解值是定义为Nullable还是NotNullable_Graphql_Graphql Js_Transit_Sanctuary - Fatal编程技术网

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
区分开来?换句话说,您想从值推断类型吗?