api-platform / api-platform/core

[GraphQL] ID field is added although not specified

Open
#5,461 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
PHP
Stars
2.6k
Forks
980
Avg merge
2d 5h
Merged PRs (30d)
48

Description

**API Platform version(s) affected**: 3.1.2

**Description**
When defining a new type, an ID field is automatically added to the generate schema. This should not be the case.

**How to reproduce**

Take the following entity as example:

**Entity**

```php
#[
API\ApiResource(
graphQlOperations: [
new Query(
args: [],
),
]
)
]
class Service
{
#[
API\ApiProperty(identifier: true),
Assert\NotNull,
]
private string $name = "abc-123";
#[
Assert\NotNull,
]
private string $version = "0.1.0";
#[
Assert\NotNull,
]
private string $schema = "";

// .. getter/setter
}
```

This generates the following schema

![2023-03-15_13 55 46](https://user-images.githubusercontent.com/4409904/225315178-5212afaf-925b-4517-bccc-b8a105b46be8.png)

As you can see, the ID is in the schema but it is not defined. An external service is checking this schema, and does not allow this field to be there.

**Possible Solution**

A new type can be configure to not implement the `Node` interface. That is where the `id` fiel is coming from.

**Additional Context**
-

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.