Skip to content
Snippets Groups Projects
Unverified Commit 1c8e6710 authored by Coung Ngo's avatar Coung Ngo :guitar: Committed by GitLab
Browse files

Merge branch 'hly-fix-graphiql-multiple-queries' into 'master'

Fix GraphQL Explorer error with multiple queries

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/169435



Merged-by: default avatarCoung Ngo <cngo@gitlab.com>
Approved-by: default avatarCoung Ngo <cngo@gitlab.com>
Reviewed-by: default avatarHeinrich Lee Yu <heinrich@gitlab.com>
Co-authored-by: default avatarHeinrich Lee Yu <heinrich@gitlab.com>
parents 2052dacf 93c3e0a8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -19,8 +19,28 @@ const apolloClient = createDefaultClient(
const graphiqlContainer = document.getElementById('graphiql-container');
 
function apolloFetcher(graphQLParams) {
let query = gql(graphQLParams.query);
/*
GraphiQL allows multiple named operations to be declared in the editor.
When the user clicks execute, they are prompted to select one of the operations.
We must filter the query to only contain the selected operation so we execute the correct query
and avoid an `Ambiguous GraphQL document: contains 2 operations` error.
*/
if (graphQLParams.operationName) {
query = {
...query,
definitions: query.definitions.filter((definition) => {
return (
definition.kind !== 'OperationDefinition' ||
definition.name.value === graphQLParams.operationName
);
}),
};
}
return apolloClient.subscribe({
query: gql(graphQLParams.query),
query,
variables: graphQLParams.variables,
operationName: graphQLParams.operationName,
});
Loading
Loading
Loading
Loading
@@ -44,6 +44,22 @@
expect_response(%("currentUser": { "id": "#{user.to_gid}" }))
end
 
it 'allows user to execute one of multiple named queries' do
visit '/-/graphql-explorer'
fill_in_editor(
'query currentUserId { currentUser { ...UserIdFragment } } ' \
'query currentUsername { currentUser { username } } ' \
'fragment UserIdFragment on User { id }'
)
sleep 0.1 # GraphiQL needs to parse the query in the background before we click execute
click_execute_button
find('.graphiql-dropdown-item', text: 'currentUserId').click
expect_response(%("currentUser": { "id": "#{user.to_gid}" }))
end
it 'allows user to execute a mutation' do
visit '/-/graphql-explorer'
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment