GraphQL attribute types inconsistent with REST api #11699

Closed
opened 2025-12-29 21:48:45 +01:00 by adam · 3 comments
Owner

Originally created by @AdilsonTorres on GitHub (Oct 6, 2025).

NetBox Edition

NetBox Community

NetBox Version

v4.x

Python Version

3.10

Steps to Reproduce

  1. Request a graphql model like:
    {
    site_list{
    id,
    name,
    region {
    id
    name
    }
    }
    }

Expected Behavior

A list with correct types, like the REST api:
{
"data": {
"site_list": [
{
"id": 24,
"name": "Butler Communications",
"region": {
"id": 40,
"name": "North Carolina"
}
},
...

Observed Behavior

A list with wrong types in the int values as string, I found a closed issue but with no conclusion (#11472):

{
"data": {
"site_list": [
{
"id": "24",
"name": "Butler Communications",
"region": {
"id": "40",
"name": "North Carolina"
}
},
...

Originally created by @AdilsonTorres on GitHub (Oct 6, 2025). ### NetBox Edition NetBox Community ### NetBox Version v4.x ### Python Version 3.10 ### Steps to Reproduce 1. Request a graphql model like: { site_list{ id, name, region { id name } } } ### Expected Behavior A list with correct types, like the REST api: { "data": { "site_list": [ { "id": 24, "name": "Butler Communications", "region": { "id": 40, "name": "North Carolina" } }, ... ### Observed Behavior A list with wrong types in the int values as string, I found a closed issue but with no conclusion (#11472): { "data": { "site_list": [ { "id": "24", "name": "Butler Communications", "region": { "id": "40", "name": "North Carolina" } }, ...
adam added the type: bug label 2025-12-29 21:48:45 +01:00
adam closed this issue 2025-12-29 21:48:45 +01:00
Author
Owner

@jnovinger commented on GitHub (Oct 9, 2025):

Thank you for the report, @AdilsonTorres . I believe this behavior is actually working as designed and is part of the GraphQL specification.

The GraphQL ID scalar type is defined by the GraphQL spec to be "serialized in the same way as a String" even though it represents a unique identifier.

From the GraphQL specification:

"The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human‐readable."

Strawberry GraphQL (which NetBox uses) explicitly documents that ID is "a specialised String for representing unique object identifiers." This was previously discussed in detail in #11472, where we confirmed that NetBox 4.x's Strawberry GraphQL implementation correctly follows the GraphQL specification.

While this does differ from the REST API's behavior, it appears to be the correct and expected behavior for GraphQL APIs. Clients should treat ID values as opaque identifiers regardless of their serialization format.

@jnovinger commented on GitHub (Oct 9, 2025): Thank you for the report, @AdilsonTorres . I believe this behavior is actually working as designed and is part of the GraphQL specification. The GraphQL `ID` scalar type is [defined by the GraphQL spec](https://graphql.org/learn/schema/#scalar-types) to be "serialized in the same way as a String" even though it represents a unique identifier. From the GraphQL specification: > "The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human‐readable." Strawberry GraphQL (which NetBox uses) [explicitly documents](https://strawberry.rocks/docs/types/scalars#scalars) that ID is "a specialised `String` for representing unique object identifiers." This was previously discussed in detail in #11472, where we confirmed that NetBox 4.x's Strawberry GraphQL implementation correctly follows the GraphQL specification. While this does differ from the REST API's behavior, it appears to be the correct and expected behavior for GraphQL APIs. Clients should treat ID values as opaque identifiers regardless of their serialization format.
Author
Owner

@jeremystretch commented on GitHub (Oct 9, 2025):

Please also bear in mind that the REST and GraphQL APIs are completely different bests. Consistency between them has never been a design goal, as each serves different purposes.

@jeremystretch commented on GitHub (Oct 9, 2025): Please also bear in mind that the REST and GraphQL APIs are completely different bests. Consistency between them has never been a design goal, as each serves different purposes.
Author
Owner

@AdilsonTorres commented on GitHub (Oct 9, 2025):

Thanks for the answers. Trying to keep them similar indeed is not a good design.

@AdilsonTorres commented on GitHub (Oct 9, 2025): Thanks for the answers. Trying to keep them similar indeed is not a good design.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11699