Fields with basic types should support projections#196
Merged
Conversation
7bc4d63 to
f1cbb2e
Compare
The _Client API codegen_ will not generate projection types for _basic type fields_,
such as Strings, Booleans, Integers, or Floats, or arrays of any of these types.
Let's say we have the following schema:
```
type Query {
someField: Foo
}
type Foo {
stringField(arg: Boolean): String
}
```
According to the schema we should expect a _stringField projection_ on the `someField` field.
But currently this is not the case.
When generating the root projections, as well as sub-projections, we
need to consider the _fields_ with basic types that present input arguments.
To be more specific, and leveraging the schema mentioned above, the `SomeFieldProjectionRoot` _projection type_
should include a `stringField(Boolean arg)` method definition.
The changes on this PR will generate the following `stringField(Boolean arg)` method...
```
public SomeField_StringFieldProjection stringField(Boolean arg) {
SomeField_StringFieldProjection projection = new SomeField_StringFieldProjection(this, this);
getFields().put("stringField", projection);
getInputArguments().computeIfAbsent("stringField", k -> new ArrayList<>());
InputArgument argArg = new InputArgument("arg", arg);
getInputArguments().get("stringField").add(argArg);
return projection;
}
```
In addition to the `stringFeild()` method that will already exist in the `SomeFieldProjectionRoot`, such as the one
below.
```
public SomeFieldProjectionRoot stringField() {
getFields().put("stringField", null);
return this;
}
```
Note that the empty argument method will still return the _root projection_ class, in this
case `SomeFieldProjectionRoot` while the new field, the one with the argument, will return a different type,
in this case `SomeField_StringFieldProjection`.
This is the same behavior for complex types and although arguably both
could return the new type, `SomeField_StringFieldProjection`, this will
be backwards incompatible.
f1cbb2e to
687c268
Compare
Current Behavior
================
The _Client API codegen_ will not generate projection types for _scalars_. Let's say we have the following schema:
```
type Query {
ping: Foo
}
type Foo {
someField(arg: Boolean): Long
}
scalar Long
```
According to the schema we should expect a _someField projection_, but currently this is not the case.
Suggested Improvement
=====================
When generating the root projections, as well as sub-projections, we
need to consider the _fields_ with basic types that present input arguments.
To be more specific, and leveraging the schema mentioned above, the `SomeFieldProjectionRoot` _projection type_
should include a `ping(Boolean arg)` method definition.
The changes on this PR will generate the following `ping(Boolean arg)` method...
```
public SomeField_PingProjection ping(Boolean arg) {
SomeField_PingProjection projection = new SomeField_PingProjection(this, this);
getFields().put("ping", projection);
getInputArguments().computeIfAbsent("ping", k -> new ArrayList<>());
InputArgument argArg = new InputArgument("arg", arg);
getInputArguments().get("ping").add(argArg);
return projection;
}
```
In addition to the `ping()` method that will already exist in the `SomeFieldProjectionRoot`, such as the one
below.
```
public SomeField_PingProjection ping() {
SomeField_PingProjection projection = new SomeField_PingProjection(this, this);
getFields().put("ping", projection);
return projection;
}
```
srinivasankavitha
approved these changes
Jul 26, 2021
Fields with scalars should support projections
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
The Client API codegen will not generate projection types for basic type fields, such as Strings, Booleans, Integers, or Floats, or arrays of any of these types. Let's say we have the following schema:
According to the schema we should expect a stringField projection on the
someFieldfield, but currently this is not the case.Suggested Improvement
When generating the root projections, as well as sub-projections, we
need to consider the fields with basic types that present input arguments.
To be more specific, and leveraging the schema mentioned above, the
SomeFieldProjectionRootprojection typeshould include a
stringField(Boolean arg)method definition.The changes on this PR will generate the following
stringField(Boolean arg)method...In addition to the
stringFeild()method that will already exist in theSomeFieldProjectionRoot, such as the onebelow.
Backwards Compatibility
Note that the empty argument method will still return the root projection class, in this case
SomeFieldProjectionRootwhile the new field, the one with the argument, will return a different type, in this caseSomeField_StringFieldProjection.This is the same behavior for complex types and although arguably both could return the new type,
SomeField_StringFieldProjection, this will be backwards incompatible.