graphql / graphql/graphql-js

astFromValue fails with a custom scalar serializing to an object value

Open
#4,085 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
20.3k
Forks
2.1k
Avg merge
44m
Merged PRs (30d)
6

Description

When you have a scalar with a `serialize` function that returns an object, it is not possible to convert it to AST.
So it doesn't allow you to print a schema that has an input value with an object as a default value.

Reproduction -> https://github.com/graphql/graphql-js/pull/4086
Proposed fix -> https://github.com/graphql/graphql-js/pull/4087

```ts
const JSONScalar = new GraphQLScalarType({
name: "JSON",
serialize(value) {
return value;
},
});

const schema = new GraphQLSchema({
types: [JSONScalar],
query: new GraphQLObjectType({
name: "Query",
fields: {
test: {
type: GraphQLString,
args: {
i: {
type: JSONScalar,
defaultValue: { object: true },
},
},
},
},
}),
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.