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

Variables and Context #1

Merged
merged 2 commits into from
Dec 16, 2015
Merged

Variables and Context #1

merged 2 commits into from
Dec 16, 2015

Conversation

bruce
Copy link
Contributor

@bruce bruce commented Dec 16, 2015

Besides arguments, there are two additional sources of values for resolution: execution variables (which should relate to variables declared in the query document and probably provided by HTTP params, etc) and context (which are additional, system-provided values like the current user, etc). Notably, the difference here is that variables are should be of type %{binary => any}, where context can be %{any => any} (and, in practice, will probably be %{atom => any}).

This PR deconflates execution variables and context and adds testing, changes needed to ensure variables are being looked up correctly.

@benwilson512
Copy link
Contributor

Question: How are the variables passed along with a request? Are they additional http parameters or something? Is there a special section of the graphql doc for them?

@bruce
Copy link
Contributor Author

bruce commented Dec 16, 2015

Example:

Yes; it's really up to how you feed the values into ExGraphQL.run, but the expected usage would be:

POST /api/linen?thingId=12
Content-Type: application/graphql

query GimmeThingByVariable($thingId: Int!) {
  thing(id: $thingId) {
    name
  }
}

@bruce
Copy link
Contributor Author

bruce commented Dec 16, 2015

And that's the "client provides the document" approach. Later, if we stored the docs server-side, it could be something like:

POST /api/linen?doc=nameOfDocumentWithManyOperations&operation=GimmeThingByVariable&thingId=12
Content-Type: application/graphql

Where doc would pull in the appropriate query document from storage, and operation would select the operation to execute (since you can actually have multiple operations declared in a document; you just have to select a single one to execute)

@bruce
Copy link
Contributor Author

bruce commented Dec 16, 2015

Oh, boy did this turn out to be more complex than I thought. Pretty good result, though -- support for error reporting on missing values (but still executing the document), support for defaults, etc. I'm going to merge this down and make a PR to support these changes in our project.

@bruce bruce removed the Status:WIP label Dec 16, 2015
bruce added a commit that referenced this pull request Dec 16, 2015
@bruce bruce merged commit af8f9a9 into master Dec 16, 2015
@bruce bruce deleted the variables-and-context branch December 16, 2015 21:25
binaryseed referenced this pull request in binaryseed/absinthe Oct 24, 2018
Delegate to NG for Schema Hiding
aaronrenner added a commit to Boulevard/absinthe that referenced this pull request Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants