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

Add parentType to path to avoid path ambiguity #2669

Merged
merged 7 commits into from Jun 28, 2020

Conversation

benjie
Copy link
Member

@benjie benjie commented Jun 19, 2020

Imagine you have the schema:

type A {
  int: Int
  union: C
}
type B {
  int: Int
  union: C
}
union C = A | B
type Query {
  root: C
}

You could write the query:

{
  root {
    ... on A {
      union {
        ... on A {
          alias1: union { # EXAMPLE1
            int
          }
          alias2: union {
            int
          }
        }
        ... on B {
          alias1: union {
            int
          }
          alias2: union {
            int
          }
        }
      }
    }
    ... on B {
      union {
        ... on A {
          alias1: union { # EXAMPLE2
            int
          }
          alias2: union {
            int
          }
        }
        ... on B {
          alias1: union {
            int
          }
          alias2: union {
            int
          }
        }
      }
    }
  }
}

In the resolver for A.union, in resolveInfo (the fourth argument to resolve) you would not be able to tell if you are in position EXAMPLE1 or EXAMPLE2 without looking into the loc data in fieldNodes. This makes it challenging to write certain classes of lookahead engine.

Namely in both EXAMPLE1 and EXAMPLE2, you have:

  • parentType: 'A'
  • path: {key: 'alias1', prev: { key: 'union', prev: { key: 'root' } } }

So the path is ambiguous. This PR adds parentType to the Path type, so these paths would become:

  • EXAMPLE1: path: {key: 'alias1', parentTypeName: 'A', prev: { key: 'union', parentTypeName: 'A', prev: { key: 'root', parentTypeName: 'Query' } } }
  • EXAMPLE2: path: {key: 'alias1', parentTypeName: 'A', prev: { key: 'union', parentTypeName: 'B', prev: { key: 'root', parentTypeName: 'Query' } } }

Note the subtle difference between the A/B parentTypeName in the middle of the path.

@IvanGoncharov IvanGoncharov added the PR: feature 🚀 requires increase of "minor" version number label Jun 19, 2020
@benjie benjie marked this pull request as ready for review June 19, 2020 17:13
@benjie
Copy link
Member Author

benjie commented Jun 19, 2020

Ready for review; I've added a test that tests a union/list too.

@benjie
Copy link
Member Author

benjie commented Jun 24, 2020

@IvanGoncharov Just a ping in case the "request review" above didn't hit your radar.

Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
@benjie
Copy link
Member Author

benjie commented Jun 25, 2020

Suggestion merged; I have not corrected all the other places in the file that use execute rather than executeSync.

@IvanGoncharov IvanGoncharov merged commit b489677 into graphql:master Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature 🚀 requires increase of "minor" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants