E530 Fields with basic types should support projections by berngp · Pull Request #196 · Netflix/dgs-codegen · GitHub
[go: up one dir, main page]

Skip to content

Fields with basic types should support projections#196

Merged
berngp merged 3 commits intomasterfrom
feature/basic-type-projects
Jul 26, 2021
Merged

Fields with basic types should support projections#196
berngp merged 3 commits intomasterfrom
feature/basic-type-projects

Conversation

@berngp
Copy link
Contributor
@berngp berngp commented Jul 23, 2021

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:

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.

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 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;
}

Backwards Compatibility

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.

@berngp berngp force-pushed the feature/basic-type-projects branch from 7bc4d63 to f1cbb2e Compare July 23, 2021 23:01
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.
@berngp berngp force-pushed the feature/basic-type-projects branch from f1cbb2e to 687c268 Compare July 23, 2021 23:03
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;
}
```
Fields with scalars should support projections
@berngp berngp merged commit 2ebe55d into master Jul 26, 2021
@berngp berngp deleted the feature/basic-type-projects branch July 26, 2021 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0