You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How get selectionSet from DataFetchingEnvironment if selection is FragmentSpread #303
DataFetchingEnvironment.fields has information of selected fields.
But when I run below query, I can't find a way to know the field selectionSet at emplPositionClasses field. Because it is explicit defined fragment, so the instance of selection in emplPositionClasses selectionSet is FragmentSpread. and there is no methods to get selectionSet on FragmentSpread.
For the other two type of selection, Field and InlineFragment, there are methods to get selectionSet, so inline fragment has no issue.
the field emplPositionClasses type is EmplPositionClassConnection
query {
mantle {
emplPositionClasses {
...EmplPositionClassesFragment
}
}
}
fragment EmplPositionClassesFragment on EmplPositionClassConnection {
edges {
node {
id
emplPositionClassId
title
description
}
}
}
So is it reasonable to also add getSelectionSet() method on class FragmentSpread?
Yes, you are correct, I believe this is a defect: you would need to have
available the FragmentDefinition referenced by the FragmentSpread to know
what fields the fragment spread is spreading. But in
DataFetchingEnvironment, nothing has a reference to that fragment. I
believe adding the `ExecutionContext` to the DataFetching environment has
been suggested elsewhere. We should go ahead and do something like that.
However, `FragmentSpread` is an AST node that describes the AST. In this
case, it's a fragment spread and it has no children. Directly having a
reference to its FragmentDefinition is not appropriate for an AST class, I
think, since its focus is to model a language node as it appeared in the
document.
Thank you for reporting this! Did you find a workaround?
On Wed, Jan 18, 2017 at 2:15 AM, Jimmy Shen ***@***.***> wrote:
DataFetchingEnvironment.fields has information selected fields.
But when I run below query, I can't find a way to know the field
selectionSet at emplPositionClasses field. Because it is explicit defined
fragment, so it is the instance of selection in emplPositionClasses
selectionSet is FragmentSpread. and there is no methods to get selectionSet
on FragmentSpread.
For the other two type of selection, Field and InlineFragment, there are
methods to get selectionSet, so inline fragment has no issue.
the field emplPositionClasses type is EmplPositionClassConnection
query {
mantle {
emplPositionClasses {
...EmplPositionClassesFragment
}
}
}
fragment EmplPositionClassesFragment on EmplPositionClassConnection {
edges {
node {
id
emplPositionClassId
title
description
}
}
}
So is it reasonable to also add getSelectionSet() method on class
FragmentSpread?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#303>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AANWZePrW1abBlaorCEmjTu7FQy8B8d_ks5rTbwlgaJpZM4LmjVJ>
.
No, I did not find walkaround.
I think it can also add selectionSet then it will work. Field and InlineFragment has it.
???? iPhone
? 2017?1?18??22:59?Dmitry Minkovsky <notifications@github.com<mailto:notifications@github.com>> ???
Yes, you are correct, I believe this is a defect: you would need to have
available the FragmentDefinition referenced by the FragmentSpread to know
what fields the fragment spread is spreading. But in
DataFetchingEnvironment, nothing has a reference to that fragment. I
believe adding the `ExecutionContext` to the DataFetching environment has
been suggested elsewhere. We should go ahead and do something like that.
However, `FragmentSpread` is an AST node that describes the AST. In this
case, it's a fragment spread and it has no children. Directly having a
reference to its FragmentDefinition is not appropriate for an AST class, I
think, since its focus is to model a language node as it appeared in the
document.
Thank you for reporting this! Did you find a workaround?
On Wed, Jan 18, 2017 at 2:15 AM, Jimmy Shen ***@***.******@***.***>> wrote:
DataFetchingEnvironment.fields has information selected fields.
But when I run below query, I can't find a way to know the field
selectionSet at emplPositionClasses field. Because it is explicit defined
fragment, so it is the instance of selection in emplPositionClasses
selectionSet is FragmentSpread. and there is no methods to get selectionSet
on FragmentSpread.
For the other two type of selection, Field and InlineFragment, there are
methods to get selectionSet, so inline fragment has no issue.
the field emplPositionClasses type is EmplPositionClassConnection
query {
mantle {
emplPositionClasses {
...EmplPositionClassesFragment
}
}
}
fragment EmplPositionClassesFragment on EmplPositionClassConnection {
edges {
node {
id
emplPositionClassId
title
description
}
}
}
So is it reasonable to also add getSelectionSet() method on class
FragmentSpread?
-
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#303>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AANWZePrW1abBlaorCEmjTu7FQy8B8d_ks5rTbwlgaJpZM4LmjVJ>
.
Yes, they have them because these classes represent field and inline fragment nodes in the GraphQL query language. In the query language, those types of nodes can have a selection set. But the FragmentSpread, which models a fragment spread as it occurs in a written GraphQL query, by definition does not have a selection set.
See the Facebook reference implementation/modeling: FieldNode vs InlineFragmentNode vs FragmentSpreadNode. FieldNode and InlineFragmentNode have selection sets. FragmentSpreadNode does not.
But yes, of course, it is convenient to have those fragment definitions and their selection sets during execution. The fragment definitions are available in the ExecutionContext, which should be exposed in the DataFetchingEnvironment.
I only find latest java with graphql-java-2017-01-15T22-16-50.jar. It seems #301 not in there yet. So I will need to wait the latest build to give a try.
From stepping through the code I can see that the actual ExecutionContext is never passed to DataFetchingEnvironment (or the new DataFetchingEnvironmentImpl) as the context parameter (line 31 of ExecutionStrategy). Instead executionContext.getRoot() is passed as that param. Is this intentional? Changing it to pass the ExecutionContext would give us access to fragment definitions.
Hi @mrcirillo, thanks for investigating. Yes, this is intentional. executionContext.getRoot() in this case returns what is the "context" inside the DataFetcher, aka the root of the whole GraphQL execution, aka what you passed to GraphQL#execute() as the source.
Indeed, we can pass the whole ExecutionContext into the DataFetcher via the DataFetchingEnvironment to get the fragment definitions. I think we should make this change.
Activity
Fixed issues in getActualLocalizeFields(). Now it checks InlineFragme…
dminkovsky commentedon Jan 18, 2017
shendepu commentedon Jan 18, 2017
dminkovsky commentedon Jan 18, 2017
Yes, they have them because these classes represent field and inline fragment nodes in the GraphQL query language. In the query language, those types of nodes can have a selection set. But the
FragmentSpread, which models a fragment spread as it occurs in a written GraphQL query, by definition does not have a selection set.See the Facebook reference implementation/modeling: FieldNode vs InlineFragmentNode vs FragmentSpreadNode.
FieldNodeandInlineFragmentNodehave selection sets.FragmentSpreadNodedoes not.But yes, of course, it is convenient to have those fragment definitions and their selection sets during execution. The fragment definitions are available in the
ExecutionContext, which should be exposed in theDataFetchingEnvironment.Related perhaps #301 #260
shendepu commentedon Jan 19, 2017
I only find latest java with graphql-java-2017-01-15T22-16-50.jar. It seems #301 not in there yet. So I will need to wait the latest build to give a try.
misterzirillo commentedon Jan 21, 2017
From stepping through the code I can see that the actual
ExecutionContextis never passed toDataFetchingEnvironment(or the newDataFetchingEnvironmentImpl) as thecontextparameter (line 31 ofExecutionStrategy). InsteadexecutionContext.getRoot()is passed as that param. Is this intentional? Changing it to pass theExecutionContextwould give us access to fragment definitions.dminkovsky commentedon Jan 21, 2017
Hi @mrcirillo, thanks for investigating. Yes, this is intentional.
executionContext.getRoot()in this case returns what is the "context" inside the DataFetcher, aka the root of the whole GraphQL execution, aka what you passed toGraphQL#execute()as the source.Indeed, we can pass the whole
ExecutionContextinto theDataFetchervia theDataFetchingEnvironmentto get the fragment definitions. I think we should make this change.misterzirillo commentedon Jan 21, 2017
I've already done it :) I'll make a PR soon.
dminkovsky commentedon Jan 21, 2017
Oh cool. Thanks. Something like https://github.com/graphql/graphql-js/blob/v0.8.2/src/type/definition.js#L560? (aka the
DataFetchingEnvironment)dminkovsky commentedon Jan 21, 2017
Also please see d1af3ac the most recent commit on master. Thank you!
Add fragment definitions and execution id to DataFetchingEnvironment (f…
Merge remote-tracking branch 'upstream/master'