-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Graphql integration test (#954)
* Graphql IT test * Update * Remove jsonignore * Split test * make build pass * fix graphql it * Sync test with old groovy test
- Loading branch information
1 parent
6254f83
commit b0aaf30
Showing
7 changed files
with
712 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...rs/src/main/java/com/yahoo/elide/contrib/testhelpers/graphql/VariableFieldSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2019, Yahoo Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
package com.yahoo.elide.contrib.testhelpers.graphql; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A Jackson serializer for String entity field. | ||
* <p> | ||
* {@link VariableFieldSerializer} serializes a String field differently when value can both represents a concrete value | ||
* or a GraphQL variable. On concrete value, it outputs the original value unmodified and quoted; on variable value, it | ||
* does not quote the original value. | ||
* <p> | ||
* For example, given the following entity: | ||
* <pre> | ||
* {@code | ||
* public class Book { | ||
* | ||
* {@literal @}JsonSerialize(using = VariableFieldSerializer.class, as = String.class) | ||
* private String title; | ||
* } | ||
* } | ||
* </pre> | ||
* A {@code Book(title="Java Concurrency in Practice")} serializes to | ||
* <pre> | ||
* {"title": "Java Concurrency in Practice"} | ||
* </pre> | ||
* However a {@code Book(title="$titlePassedByClient")} serializes to | ||
* <pre> | ||
* {"title": $titlePassedByClient} | ||
* </pre> | ||
* Note in the 1st serialization {@code title} value is quoted while the 2nd serialization it is not. | ||
* <p> | ||
* To serialize a String entity field in such a way, add the following annotation to the field, as shown above: | ||
* <pre> | ||
* {@code | ||
* {@literal @}JsonSerialize(using = VariableFieldSerializer.class, as = String.class) | ||
* } | ||
* </pre> | ||
* | ||
* @see <a href="https://graphql.org/learn/queries/#variables">Variables</a> | ||
*/ | ||
public class VariableFieldSerializer extends JsonSerializer<String> { | ||
|
||
private static final String VARIABLE_SIGN = "$"; | ||
|
||
@Override | ||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
if (value.startsWith(VARIABLE_SIGN)) { | ||
// this is a variable | ||
gen.writeRawValue(value); | ||
} else { | ||
gen.writeString(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.