Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global ID mapping does not work with manual id assignment on type in relay django #541

Open
Elawphant opened this issue Jun 3, 2024 · 3 comments
Labels
question Further information is requested

Comments

@Elawphant
Copy link

Elawphant commented Jun 3, 2024

According to documentation something like this

@strawberry_django.type(Author, filters=AuthorFilter, order=AuthorOrder)
class AuthorNode(strawberry.relay.Node):
    id: strawberry.relay.GlobalID = strawberry_django.field()
    books_connection: ListConnectionWithTotalCount[Annotated["BookNode", strawberry.lazy(
        "graph_api.gql.nodes.book_node"
    )]] = strawberry_django.connection(
        field_name="books",
        extensions=[IsAuthenticated()],
    )
    ```
    
   The response comes with ids with pk values
   ```json
   {
  "data": {
    "authorsConnection": {
      "edges": [
        {
          "node": {
            "id": "1",
          }
        },
        {
          "node": {
            "id": "2",
          }
        }
      ],
      "totalCount": 2
    }
  }
}

However this works properly

@strawberry_django.type(Author, filters=AuthorFilter, order=AuthorOrder, fields=["id"]) # note that I have set the id via fields parameter instead of assigning it as a field
class AuthorNode(strawberry.relay.Node):
    books_connection: ListConnectionWithTotalCount[Annotated["BookNode", strawberry.lazy(
        "graph_api.gql.nodes.book_node"
    )]] = strawberry_django.connection(
        field_name="books",
        extensions=[IsAuthenticated()],
    )
    ```
@Elawphant Elawphant added the bug Something isn't working label Jun 3, 2024
@bellini666
Copy link
Member

Hey @Elawphant ,

When using @strawberry_django.type and inheriting the type from Node it will automatically have an id: GlobalID with a custom resolver that will return the correct value in it.

Is there a reason to why you are trying to define it yourself?

@bellini666 bellini666 added the question Further information is requested label Jun 3, 2024
@Elawphant
Copy link
Author

The reason was to keep the types defined with all fields the same way.
I made an addon on top of strawberry_django which makes the modules from the models. Here's the link
Strawberry Jam 🍓
@bellini666 I would appreciate some review/feedback on the generated modules, whether they are providing configurations in accordance with the best practices for strawberry django. Also I want to make the tests generation.

@bellini666
Copy link
Member

@Elawphant ahhh I see.

I need to think about how to workaround that properly. In the meantime, you can probably skip the id field when creating a type that inherits from Node.

Regarding the lib, very interesting! Will take a look at it as soon as I can 😊

@bellini666 bellini666 removed the bug Something isn't working label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants