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

[resolvers-composition] Use Namespace-types without depth limit #4609

Open
4 tasks
Tracked by #5201 ...
Drilmo opened this issue Aug 1, 2022 · 3 comments
Open
4 tasks
Tracked by #5201 ...

[resolvers-composition] Use Namespace-types without depth limit #4609

Drilmo opened this issue Aug 1, 2022 · 3 comments

Comments

@Drilmo
Copy link

Drilmo commented Aug 1, 2022

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

When I use namespace-types I can't use resolvers-composition, because the resolver-composition does not allow depth, but only : ${typeName}.${field}

Namespace-types : https://graphql-rules.com/rules/mutation-namespaces

Code line : https://github.com/ardatan/graphql-tools/blob/master/packages/resolvers-composition/src/resolvers-composition.ts#L69

To Reproduce
Steps to reproduce the behavior:

Namespace-types : https://graphql-rules.com/rules/mutation-namespaces

and

https://www.graphql-tools.com/docs/resolvers-composition#supported-path-matcher-format

Expected behavior
Based on the documentation:
Capture d’écran 2022-08-01 à 16 11 05

If namespace-types are possible we should be able to do this kind of thing:

  • Query.User.*
  • Query.User.Group.*
  • Mutation.User.!{createUser, login}

Environment:

  • @graphql-tools/resolvers-composition:

Thank you in advance for your consideration and feedback

@ardatan
Copy link
Owner

ardatan commented Aug 1, 2022

Resolvers Composition follows the signature of resolvers which is always Type.field. So due to the resolution algorithm of GraphQL-js, I don't think it is possible to make this work in that way because each resolver is independent from the resolution of the parent.

I am not sure "namespace-types" is part of GraphQL Spec or GraphQL-js implementation. It seems too specific for a library.
But I'm open for contributions if it is something we can support in GraphQL Tools without adding a dependency or breaking the other users.

@Drilmo
Copy link
Author

Drilmo commented Aug 3, 2022

Hi @ardatan,

I managed to switch to Debug mode, and the namespace type is usable in this example:

const typeDefs = gql`
  type Mutation {
    article: ArticleMutations
  }

   type Query {
    article: ArticleQuery
  }

  type ArticleMutations {
    like: Boolean
    unlike: Boolean
  }

  type ArticleQuery {
    article(id: ID): Article
    articles: [Article!]
  }

`;

const resolvers = {
  Mutation: {
    article: () => ({}), // namespace-type
  },
  ArticleMutations: {
    like: () => { /* resolver code */ },
    unlike: () => { /* resolver code */ },
  },
  Query: {
    article: () => ({}), // namespace-type
  },
  ArticleQuery: {
    article: (id) => { /* resolver code */ },
    articles: () => { /* resolver code */ },
  },
};

it just needs to be written like this:

  • ArticleMutations.*
  • ArticleMutations.like
  • ArticleMutations.!like
  • ArticleQuery.*
  • ArticleQuery.article

I think an update of the doc would be good for users.

thank you in advance for your feedback

@ardatan
Copy link
Owner

ardatan commented Aug 3, 2022

Oh now I see what you mean. Would you create a PR for the docs? I think it would be nice to have it written by your perspective.

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