我有一个特殊的 GraphQL 标量类型表示日期时间的库 https://www.npmjs.com/package/graphql-iso-date对象。但是,我有一个情况,从 MySQL 返回值“0000-00-00 00:00:00”,这表明它无法解析。我本质上想始终解决这个问题null
.
在我的模式中,我总是可以放置一个自定义解析器,类似于:
import gqlDate from 'graphql-iso-date';
const MyType = new gql.GraphQLObjectType({
name: 'Type',
description: 'This is a GraphQL type.',
fields: () => {
return {
datetime: {
type: gqlDate.GraphQLDateTime,
description: 'The datetime field of my type.',
resolve: (record) => {
return record === '0000-00-00 00:00:00' ? null : record;
}
}
};
}
});
但我希望有一种方法可以将其包装在如下所示的类型中:
const CustomDateTimeType = new gql.GraphQLType({
name: 'CustomDateTime',
type: gqlDate.DateTimeType,
resolve: (record) => {
return record === '0000-00-00 00:00:00' ? null : record;
}
});
我能想到的另一种方法是 UnionType,但这似乎很笨拙。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)