question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when using custom scalars inside .graphql schema

See original GitHub issue

Type generation fails with Unable to resolve reference to type MyCustomScalar if the schema contains custom scalars. This happens only if using .graphql schema when calling Introspection.fromSchemaDefinition. The reason for this is that when using schema first in graphql-dotnet you have to register your custom scalars directly after parsing the schema, here is the docs and here is how it looks like:

var schema = Schema.For(...);
schema.RegisterType(new MyBooleanGraphType());

I was working on a fix for this and my idea was to parse the schema to get the custom scalars out of it and register the types, which would look like this (pseudocode):

let graphqlServer = GraphQL.Types.Schema.For(definition, configureSchemaBuilder)
let types = GraphQLParser.Parser.Parse(definition) // parse the schema into a graphql document to filter scalars

getCustomScalars types |> buildGraphTypes |> |> Seq.iter graphqlServer.RegisterType
let schemaJson = graphqlServer.ExecuteAsync(...)

This seems to work, however it does seem pretty inefficient since the schema is parsed many times - first graphq-dotnet parses it in GraphQL.Types.Schema.For, then I parse it again to get the scalars, then Snowflaqe parses it once more to convert from json to its internal representation.

So I started thinking that maybe we could parse the result of GraphQLParser.Parser.Parse(definition) directly into the internal data structures Snowflaqe uses for type generation? This of course would only be necessary for schemas defined in .graphql. Any thoughts on this, @Zaid-Ajaj ?

FYI, @Yakimych @danielstarck 🙂

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Zaid-Ajajcommented, Jun 4, 2022

Any particular reason you don’t want to depend on the parser from graphql-dotnet?

I would rather rely on deriving the types from the result of the standard introspection query because the output of it is predictable and won’t change based on different versions of a specific parser, graphql-dotnet in this case

0reactions
Zaid-Ajajcommented, Jun 5, 2022

I would rather not have to write and maintain my own parser if possible to replace the one from graphql-dotnet. Tweeking it is a lot easier than rebuilding it, although I agree it is not ideal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom scalars - Apollo GraphQL Docs
Defining a custom scalar​​ You can now use MyCustomScalar in your schema anywhere you can use a default scalar (e.g., as the type...
Read more >
error handling in custom scalar type deserialization #927
It indicates invalid literals via returning null (not exceptions). This is because the parse will handle the AST literals mostly in shape, but...
Read more >
Custom Scalar in Graphql-java
We are planning use Graphql as backend server in our application. We choose Graphql-Java to develop our POC. We came across a stituation...
Read more >
Scalars | GraphQL Java
The serialize MUST ONLY allow graphql.schema.CoercingSerializeException to be thrown from it. This indicates that the value cannot be serialized into an ...
Read more >
GraphQL Server Using Spring Boot, Part II — Scalars
GraphQL scalars are atomic (indivisible) values, meaning that they can only be selected as a whole and cannot be divided into multiple fields....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found