-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
b6dfc63
commit e06d69b
Showing
57 changed files
with
1,253 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ | |
*/ | ||
public interface GraphQLParametrizedInput { | ||
|
||
GraphQLParametrizedInput deepCopy(); | ||
|
||
} |
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
76 changes: 71 additions & 5 deletions
76
src/main/java/com/kobylynskyi/graphql/codegen/model/graphql/GraphQLResponseProjection.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,24 +1,90 @@ | ||
package com.kobylynskyi.graphql.codegen.model.graphql; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
|
||
/** | ||
* The implementation class should basically contain the fields of the particular type which | ||
* should be returned back to the client. | ||
* The implementation class should contain the fields of the particular type that should be returned to the client. | ||
*/ | ||
public abstract class GraphQLResponseProjection { | ||
|
||
protected final List<GraphQLResponseField> fields = new ArrayList<>(); | ||
/** | ||
* Contains all response projection fields, where: | ||
* key - is the name+alias pair (where alias is nullable) | ||
* value - is GraphQLResponseField which represents the response projection field | ||
*/ | ||
protected final Map<Pair<String, String>, GraphQLResponseField> fields = new LinkedHashMap<>(); | ||
|
||
protected GraphQLResponseProjection() { | ||
} | ||
|
||
protected GraphQLResponseProjection(GraphQLResponseProjection projection) { | ||
if (projection == null) { | ||
return; | ||
} | ||
projection.fields.values().forEach(this::add$); | ||
} | ||
|
||
protected GraphQLResponseProjection(List<? extends GraphQLResponseProjection> projections) { | ||
if (projections == null) { | ||
return; | ||
} | ||
for (GraphQLResponseProjection projection : projections) { | ||
if (projection == null) { | ||
continue; | ||
} | ||
projection.fields.values().forEach(this::add$); | ||
} | ||
} | ||
|
||
@SuppressWarnings({"checkstyle:MethodName", "java:S100"}) | ||
public abstract GraphQLResponseProjection deepCopy$(); | ||
|
||
@SuppressWarnings({"checkstyle:MethodName", "java:S100", "java:S3824"}) | ||
protected void add$(GraphQLResponseField responseField) { | ||
Pair<String, String> nameAndAlias = new Pair<>(responseField.getName(), responseField.getAlias()); | ||
GraphQLResponseField existingResponseField = fields.get(nameAndAlias); | ||
if (existingResponseField == null) { | ||
fields.put(nameAndAlias, responseField.deepCopy()); | ||
return; | ||
} | ||
|
||
if (!Objects.equals(responseField.getParameters(), existingResponseField.getParameters())) { | ||
throw new IllegalArgumentException( | ||
String.format("Field '%s' has an argument conflict", existingResponseField.getName())); | ||
} | ||
|
||
if (responseField.getAlias() != null) { | ||
existingResponseField.alias(responseField.getAlias()); | ||
} | ||
if (responseField.getParameters() != null) { | ||
existingResponseField.parameters(responseField.getParameters().deepCopy()); | ||
} | ||
if (responseField.getProjection() != null) { | ||
GraphQLResponseProjection projectionCopy = responseField.getProjection().deepCopy$(); | ||
if (existingResponseField.getProjection() != null) { | ||
for (GraphQLResponseField field : projectionCopy.fields.values()) { | ||
existingResponseField.getProjection().add$(field); | ||
} | ||
} else { | ||
existingResponseField.projection(projectionCopy); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (fields.isEmpty()) { | ||
return ""; | ||
} | ||
StringJoiner joiner = new StringJoiner(" ", "{ ", " }"); | ||
fields.forEach(field -> joiner.add(field.toString())); | ||
for (GraphQLResponseField value : fields.values()) { | ||
joiner.add(value.toString()); | ||
} | ||
return joiner.toString(); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/kobylynskyi/graphql/codegen/model/graphql/Pair.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,50 @@ | ||
package com.kobylynskyi.graphql.codegen.model.graphql; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Class that represents a key-value pair. | ||
* | ||
* @param <K> key | ||
* @param <V> value | ||
*/ | ||
public class Pair<K, V> { | ||
|
||
private final K key; | ||
private final V value; | ||
|
||
public K getKey() { | ||
return key; | ||
} | ||
|
||
public V getValue() { | ||
return value; | ||
} | ||
|
||
public Pair(K key, V value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return key + "=" + value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return key.hashCode() * 13 + (value == null ? 0 : value.hashCode()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o instanceof Pair) { | ||
Pair<?, ?> pair = (Pair<?, ?>) o; | ||
return Objects.equals(key, pair.key) && Objects.equals(value, pair.value); | ||
} | ||
return false; | ||
} | ||
} |
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
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
Empty file.
Oops, something went wrong.