Как вы знаете, GraphQL не имеет такого типа данных, как long int. Таким образом, если число является большим, например 10000000000
, оно выдает такую ошибку: Int cannot represent non 32-bit signed integer value: 1000000000000
Для этого я знаю два решения:
- Используйте скаляры.
import { GraphQLScalarType } from 'graphql';
import { makeExecutableSchema } from '@graphql-tools/schema';
const myCustomScalarType = new GraphQLScalarType({
name: 'MyCustomScalar',
description: 'Description of my custom scalar type',
serialize(value) {
let result;
return result;
},
parseValue(value) {
let result;
return result;
},
parseLiteral(ast) {
switch (ast.kind) {
}
}
});
const schemaString = `
scalar MyCustomScalar
type Foo {
aField: MyCustomScalar
}
type Query {
foo: Foo
}
`;
const resolverFunctions = {
MyCustomScalar: myCustomScalarType
};
const jsSchema = makeExecutableSchema({
typeDefs: schemaString,
resolvers: resolverFunctions,
});
Используйте
пакет apollo-type-bigint .
Оба они преобразуют большой int в string
, и это не идеальное решение.
Пожалуйста, если вы знаете, помогите мне. Как передать большое int как число, а не строку?