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.

Namespacing/nesting queries and mutations in schema with Nexus and Shield

See original GitHub issue

Hey!

Thanks for the examples, they are super helpful 👏

I’m evaluating Nexus and Shield, and have taken the graphql-auth project as a starter example. I’ve got the project up and running, and was trying to figure out how namespacing the schema would work - for example, nest all User related queries and mutations under a User namespace, so instead of

mutation {
  login...
}

one would do

mutation {
  user {
    login...
  }
}

Same goes for queries, where one would, for example, put the feed, post and filterPosts queries under a post namespace, i.e.

{
  post {
    feed...
    filterPosts...
  }
}

However, I can’t figure out how to

  1. Do that in Nexus - what would the return type of the new ‘root’ type (i.e. the post namespace for queries) be?
  2. Is that even possible with Shield? It throws errors at me as soon as I try to make a deeper level of keys in the permissions, i.e. go from
export const permissions = shield({
  Query: {
    me: rules.isAuthenticatedUser,
    filterPosts: rules.isAuthenticatedUser,
    post: rules.isAuthenticatedUser,
  },
  Mutation: {...},
});

to

export const permissions = shield({
  Query: {
    me: rules.isAuthenticatedUser,
    posts: {
      filterPosts: rules.isAuthenticatedUser,
      post: rules.isAuthenticatedUser,
    }
  },
  Mutation: {...},
});

Not sure if this is the right place to post it @maticzav @schickling ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jhalborgcommented, Sep 16, 2019

Still not stale, go away stale bot! 😄

1reaction
maticzavcommented, Aug 1, 2019

Not stale

Read more comments on GitHub >

github_iconTop Results From Across the Web

3. Adding mutations to your API - GraphQL Nexus
Overview. In this chapter you're going to add some write capability to your API. You'll learn about: Writing GraphQL mutations; Exposing GraphQL objects...
Read more >
Ultimate Authentication using GraphQL Nexus
This tutorial requires that you have a knowledge of GraphQL queries, mutation and context. This tutorial covers the following:.
Read more >
Developing GraphQL APIs using Nexus - Formidable Labs
When developing a GraphQL API there are two popular approaches to create the GraphQL Schema: the schema-first approach and the code-first.
Read more >
nexus-shield - npm
Nexus Shield is a nexus plugin that helps you create an authorization layer for your application. It is a replacement for the provided ......
Read more >
Getting Started – GraphQL Yoga
The Query , Mutation and Subscription types are special since they act as an entry point to the graph. The GraphQL schema acts...
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