fix for #124 is incomplete
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 217
- Forks
- 116
- PR merge metrics
- No merged PRs in 30d
Description
What happened
The com.netflix.graphql.dgs.client.codegen.InputValueSerializer from com.netflix.graphql.dgs.codegen:graphql-dgs-codegen-client-core:5.1.16 did not emit a GraphQL compliant string literal causing the server to which the request was sent to error while trying to parse the GraphQL query
How to reproduce it
- Create a
schema1.graphqlsas below - Use the codegen plugin with
generateClient = true - Create a driver class as show below
- Observe the parse error when parsing the return from
.serialize
I have a failing test, too, although it was just some "hello world" failures, and does not attempt to enumerate all of the missing edge cases
Samples
schema1.graphqls
input PersonInput {
name: String
}
type Person {
name: String
}
type Query {
friends(like: PersonInput): Person
}
Driver.java
package com.example;
import com.example.gql.client.FriendsGraphQLQuery;
import com.example.gql.client.FriendsProjectionRoot;
import com.example.gql.types.PersonInput;
import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest;
import graphql.parser.Parser;
public class Driver {
public static void main(String[] args) {
final var names = new String[] {
// but unicode is already correct
"💣",
"\r\n",
"\u0000",
"\u001F",
};
for (var name : names) {
final String gql = new GraphQLQueryRequest(
FriendsGraphQLQuery.newRequest()
.like(PersonInput.newBuilder()
.name(name)
.build())
.build(),
new FriendsProjectionRoot().name()
).serialize();
System.out.printf("gql = <<%s>>%n", gql);
var doc = Parser.parse(gql);
System.out.println("doc = " + doc);
}
}
}
What was expected
GraphQLQueryRequest.serialize should return legal GraphQL query text
Versions
- id("com.netflix.dgs.codegen") version "5.1.16"
- implementation("com.netflix.graphql.dgs:graphql-dgs-client:4.9.16")
Workaround
In case someone else stumbles upon this issue, I have a work-around until it is fixed: supersede the scalars parameter and register a JSON-safe graphql.scalar.GraphqlStringCoercing:
final Map<Class<?>, Coercing<?, ?>> scalars = Map.of(String.class, new GraphqlStringCoercing() {
@Override
public String serialize(final Object input) {
final var s = (String) input;
// this one was chosen because dgs-client uses it,
// meaning it will be present everywhere GraphQLQueryRequest is
return net.minidev.json.JSONValue.escape(s);
}
});
final String gql = new GraphQLQueryRequest(
FriendsGraphQLQuery.newRequest()
.like(PersonInput.newBuilder()
.name(name)
.build())
.build(),
new FriendsProjectionRoot().name(),
scalars
).serialize();
// and now gql will parse successfully
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with com.netflix.graphql.dgs.client.codegen.InputValueSerializer and GraphQLQueryRequest.serialize, then review the linked failing test commit and the GraphQL October 2021 string-literal rules. Reproduce the examples containing carriage returns, null, and control characters with the client codegen setup. Done means serialized queries parse successfully for these cases and the relevant tests cover the escaping behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100