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

Weird error when loading a dynamic property of a type #140

Open
Dracks opened this issue Aug 30, 2024 · 5 comments
Open

Weird error when loading a dynamic property of a type #140

Dracks opened this issue Aug 30, 2024 · 5 comments

Comments

@Dracks
Copy link

Dracks commented Aug 30, 2024

Hello,

I'm trying to migrate my project MrScrooge from nestjs with graphql into swift with vapor, graphqlkit (which uses graphiti), And seems I've got some issue, not sure if it's my error or is an error on graphiti.

When I add a dynamic field into a type, to load only when I've got the request, I do it as following:

Type(MyProfile.self){
   Field("group", MyProfile.groups
}
MyProfile{
   func groups(request: Request, Parent: MyProfile){}
}

You can see this here:
Dracks/mr-scrooge@27862ab#diff-86900d9223aa878afd6fd2f942cdd076fa63c7a147fae5e22db15769e0d2ec95R63
and here:

Dracks/mr-scrooge@27862ab#diff-86900d9223aa878afd6fd2f942cdd076fa63c7a147fae5e22db15769e0d2ec95R136-R141

it ends crashing in some weird error, the error is the following:

{
  "errors": [
    {
      "message": "keyNotFound(CodingKeys(stringValue: \"id\", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: \"No value associated with key CodingKeys(stringValue: \\\"id\\\", intValue: nil) (\\\"id\\\").\", underlyingError: nil))",
      "locations": [
        {
          "line": 6,
          "column": 7
        }
      ],
      "path": [
        "me",
        "groups"
      ]
    }
  ]
}```

I look with xcode, it seem to be some error parsing the session. Any Idea of what it can be? It happens in multiple places I've got the dynamic field. 

Do you need some small example? I can try to create it. 

Thanks, 
Dracks
@NeedleInAJayStack
Copy link
Member

Hi, this is a pretty typical Swift error when you try to decode a type that doesn't have a required field. I'd double check that the data coming back from your database has the id field populated so it matches your codable model definitions.

I might be able to give use some more direct guidance if you provide the GraphQL query that failed

@Dracks
Copy link
Author

Dracks commented Sep 1, 2024

Hey, thanks for your answord.

The query was the following one:

query {
  me{
    __typename
    ... on MyProfile {
      username
      groups{
        name
        id
      }
    }
  }
}

But the debugger with breakpoints never reached the dynamic load function. And when I don't require the groups, everything work fine

Thanks,
Jaume

@NeedleInAJayStack
Copy link
Member

NeedleInAJayStack commented Sep 5, 2024

If everything worked okay when you didn't include groups, I'd try dropping a breakpoint in the groups resolver before you load the object from the database or whatever data source you're using. Since this is a decoding error, it is likely thrown when you load the group object from the underlying data source. That is, it is likely not an issue with the GraphQL setup, instead it is likely an underlying data issue, where a group that is being loaded doesn't have an id field.

@Dracks
Copy link
Author

Dracks commented Sep 5, 2024

I'm pretty sure, I already tried and never reach the group resolver. But I will try it again.

@Dracks
Copy link
Author

Dracks commented Sep 5, 2024

Hey, I tested, it never reach the resolver of the subElement, I generated a small repo that it's a minimum reproducible error (I think)

You can see it here: https://github.com/Dracks/GraphqlVaporSample

Simply run the tests, there is 2 tests, one includes the call to the groups, the other doesn't, the first one fails the other works fine.

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

No branches or pull requests

2 participants