8000 Fields with scalars should support projections by berngp · Pull Request #197 · Netflix/dgs-codegen · GitHub
[go: up one dir, main page]

Skip to content

Fields with scalars should support projections#197

Merged
berngp merged 1 commit intofeature/basic-type-projectsfrom
feature/scalar-type-projections
Jul 26, 2021
Merged

Fields with scalars should support projections#197
berngp merged 1 commit intofeature/basic-type-projectsfrom
feature/scalar-type-projections

Conversation

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

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

@berngp berngp force-pushed the feature/scalar-type-projections branch from 50938b6 to 1189200 Compare July 24, 2021 03: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;
}
```
@berngp berngp force-pushed the feature/scalar-type-projections branch from 1189200 to c09781a Compare July 24, 2021 03:07
@berngp berngp merged commit a6e1695 into feature/basic-type-projects Jul 26, 2021
@berngp berngp deleted the feature/scalar-type-projections branch July 26, 2021 18:30
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