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

Request clarification for Directives and Field Selection Merging #531

Closed
nagledb opened this issue Nov 6, 2018 · 3 comments
Closed

Request clarification for Directives and Field Selection Merging #531

nagledb opened this issue Nov 6, 2018 · 3 comments

Comments

@nagledb
Copy link

nagledb commented Nov 6, 2018

Under "Validation": "Field Selection Merging", the spec says that merging of fields is only valid when they have identical field names and arguments. However, I don't see anywhere where it addresses what to do about directives.

For each of the following, is the query valid? If so, how should it be interpreted after merging?

Case 1: one field has a directive and the other does not

{
  sample {
    text @example
    text
  }
}

Case 2: both fields have the same directive

{
  sample {
    text @example
    text @example
  }
}

Case 3: both fields have the same directive, but with different arguments

{
  sample {
    text @example(arg: 1)
    text @example(arg: 2)
  }
}

Case 4: each field has different directives

{
  sample {
    text @example1
    text @example2
  }
}

Case 5: each field has the same directives but in different orders

{
  sample {
    text @example1 @example2
    text @example2 @example1
  }
}

I recognize that the answers may depend on the outcomes of several pending RFCs:

@OlegIlyenko
Copy link
Contributor

For each of the following, is the query valid?

I believe that according to the current spec, queries in all cases are correct.

If so, how should it be interpreted after merging?

I think it is highly depends on the specific directive and its semantics. Also I think it is not quite accurate to refer to the directive interpretation process as "merging". So far, on a query side spec defines only @skip and @include directives. I believe during the execution annotated fields are analyzed independently from each other. So, for example, in a case 4 the directives never really merged in a single list. Though I feel that the description of their interaction right now is not very well explained in the spec text. I would like to propose improvements for it in the follow up PR.

@nagledb
Copy link
Author

nagledb commented Nov 7, 2018

Thanks for the explanation! I was definitely thinking about this the wrong way before.

@nagledb nagledb closed this as completed Nov 7, 2018
@peldax
Copy link

peldax commented Sep 3, 2020

Hi, I am in the process of development a server side GraphQL library for PHP. Can I ask for more clarification on this subject? How should the following queries behave?

{
  sample {
    text
    ... @skip(if: true) {
      text
    }
  }
}

Or even more complex:

{
  sample {
    text @skip(if: false)
    ... @skip(if: true) {
      text @skip(if: false)
    }
  }
}

If the directives are left out, fields get correctly merged and its completely correct and simple query.

I always thought that field merging occurs before the query execution to get final field lists with all the information necessary for execution (type condition, directives to execute, ...), also Field selection merging is located inside Validation chapter in the specs, however now I am not really sure how to proceed and how to deal with the directives.

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

3 participants