-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
780 additions
and
554 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
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
6 changes: 0 additions & 6 deletions
6
dgs-codegen/src/main/java/com/example/demo/gql/CustomRuntimeWiring.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
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
37 changes: 26 additions & 11 deletions
37
dgs-codegen/src/main/java/com/example/demo/gql/scalars/UUIDScalar.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 |
---|---|---|
@@ -1,36 +1,51 @@ | ||
package com.example.demo.gql.scalars; | ||
|
||
import com.netflix.graphql.dgs.DgsScalar; | ||
import graphql.GraphQLContext; | ||
import graphql.execution.CoercedVariables; | ||
import graphql.language.StringValue; | ||
import graphql.language.Value; | ||
import graphql.schema.Coercing; | ||
import graphql.schema.CoercingParseLiteralException; | ||
import graphql.schema.CoercingParseValueException; | ||
import graphql.schema.CoercingSerializeException; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Locale; | ||
import java.util.UUID; | ||
|
||
@DgsScalar(name = "UUID") | ||
public class UUIDScalar implements Coercing<UUID, String> { | ||
|
||
@Override | ||
public @NotNull Value<?> valueToLiteral(@NotNull Object input, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) { | ||
return StringValue.of(input.toString()); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String serialize(Object o) throws CoercingSerializeException { | ||
if (o instanceof UUID) { | ||
return ((UUID) o).toString(); | ||
} else { | ||
throw new CoercingSerializeException("Not a valid UUID"); | ||
public UUID parseLiteral(@NotNull Value<?> input, @NotNull CoercedVariables variables, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingParseLiteralException { | ||
if (input instanceof StringValue value) { | ||
return UUID.fromString(value.getValue()); | ||
} | ||
|
||
throw new CoercingParseLiteralException("Value is not a valid UUID string"); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public UUID parseValue(Object o) throws CoercingParseValueException { | ||
return UUID.fromString(o.toString()); | ||
public UUID parseValue(@NotNull Object input, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingParseValueException { | ||
return UUID.fromString(input.toString()); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public UUID parseLiteral(Object input) throws CoercingParseLiteralException { | ||
if (input instanceof StringValue) { | ||
return UUID.fromString(((StringValue) input).getValue()); | ||
public String serialize(@NotNull Object dataFetcherResult, @NotNull GraphQLContext graphQLContext, @NotNull Locale locale) throws CoercingSerializeException { | ||
if (dataFetcherResult instanceof UUID uuid) { | ||
return uuid.toString(); | ||
} | ||
|
||
throw new CoercingParseLiteralException("Value is not a valid UUID string"); | ||
throw new CoercingSerializeException("Not a valid UUID"); | ||
} | ||
} |
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.