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

Invoking Query.Data(jsonObject:) fails for queries with params #435

Closed
diegorozen opened this issue Jan 15, 2019 · 2 comments
Closed

Invoking Query.Data(jsonObject:) fails for queries with params #435

diegorozen opened this issue Jan 15, 2019 · 2 comments

Comments

@diegorozen
Copy link
Contributor

Following #51, I am trying to create a GraphQLSelectionSet via init(jsonObject: JSONObject)

The query I'm testing has a non-optional parameter 'Episode'

query Hero($episode: Episode, $withFriends: Boolean!) {
hero(episode: $episode) {
name
friends @include(if: $withFriends) {
name
}
}
}

and to JsonObject I'm passing is

{
"data": {
"hero": {
"__typename": "Droid",
"name": "R2-D2",
"friends": [{
"__typename": "Human",
"name": "Luke Skywalker"
}, {
"__typename": "Human",
"name": "Han Solo"
}, {
"__typename": "Human",
"name": "Leia Organa"
}]
}
}
}

The call fails in GraphQLExecutor.swift

throw GraphQLError("Variable \(booleanCondition.variableName) was not provided.")

The error is "Variable withFriends was not provided". The variable info: GraphQLResolveInfo was never populated because the init method calls executor.execute without specifying the variables field, which is nil by default.

Should we skip validation of input parameters when calling this method? If so, which would be the recommended way?

Thanks,
Diego

@martijnwalraven
Copy link
Contributor

Because @include(if: $withFriends) affects which data is acceptable to pass in as jsonObject, the executor needs to know the value of the withFriends variable. So it seems init(jsonObject:) should take an optional variables: parameter, which it can pass through to GraphQLExecutor#execute.

@diegorozen
Copy link
Contributor Author

Thanks @martijnwalraven

Created a PR with your suggested changes

#437

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