question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems work with the renamed field

See original GitHub issue

When I add rules to a relation field such as messages, sometimes I may be want to get the messages NOT_READ or READ in one query. Just like this:

query {
  me {
    id
    messagesNotRead: messages(where: {status: NOT_READ}, orderBy: createdAt_DESC) {
        id
        status
    }
    messages(where: {status: READ}, orderBy: createdAt_DESC) {
        id
        status
    }
  }
}

But after use this middleware, add some rules(like isAuthenticated) to the messages field of type User, the result of the query above is not worked correctly. The renamed field messagesNotRead cannot work through the validation of the messages field. The value of messagesNotRead field is just the same of messages above:

{
  "data": {
    "me": {
      "id": "cjn105vxk00110759vg8eq8gz",
      "messagesNotRead": [
        {
          "id": "cjoy6mxbm011k0759uaito9hs",
          "status": "READ"
        },
        {
          "id": "cjoy3qcsj010807595jbtqt35",
          "status": "READ"
        },
      ],
      "messages": [
        {
          "id": "cjoy6mxbm011k0759uaito9hs",
          "status": "READ"
        },
        {
          "id": "cjoy3qcsj010807595jbtqt35",
          "status": "READ"
        },
        ]
    }
  }
}

when just rename the messages without an additional messages field,the renamed field just return null, not []:

query {
  me {
    id
    messagesNotRead: messages(where: {status: NOT_READ}, orderBy: createdAt_DESC) {
        id
      	status
    }
  }
}
{
  "data": {
    "me": {
      "id": "cjn105vxk00110759vg8eq8gz",
      "messagesNotRead": null
    }
  }
}

The expected result should like this:

query {
  me {
    id
    messages(where: {status: NOT_READ}, orderBy: createdAt_DESC) {
        id
      	status
    }
  }
}
{
  "data": {
    "me": {
      "id": "cjn105vxk00110759vg8eq8gz",
      "messages": []
    }
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
pantharshit00commented, Jan 23, 2019

https://github.com/prisma/prisma/issues/3881#issuecomment-456842794

@maticzav this is totally unrelated to graphql-shield I think you can close this here 🙂

1reaction
baby1990commented, Jan 21, 2019

@baby1990, let me know if you find any further information. Maybe this could be connected to field alias, could you try that as well?

Regardless, I think it would be super useful if we could have a common ground with a reproduction example. Let me know if you could compose that. 🙂

Actually, I tried to use the custom directives to do the permission instead of graphql-shield. But the problems not resolved. So I don’t think there is something wrong with graphql-shield.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems work with the renamed field when using graphql ...
When I use graphql-prisma / graphql-yoga / graphql-shield together to perform a backend service, the renamed field not work.
Read more >
Problem renaming a field in a query - Microsoft Community
My user wants me to rename some fields in a query, but it's not working. If I put in the Field column either...
Read more >
Unable to rename work item field - Visual Studio Feedback
Resolved the issue. There was data in the field for several work items. Once the data was cleared I was able to delete...
Read more >
Problems Renaming Fields with Make Feature Layer
If you are on 10.2 +, consider using the Alter Field GP tool instead if you can't get Make Feature Layer working. ·...
Read more >
Rename field problem - Logstash - Discuss the Elastic Stack
I suspect that you are storing field names that are getting extracted including quotation characters in the field name. You could remove them ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found