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

Rename resolveFields to query in the itemAPI #5451

Merged
merged 6 commits into from
Apr 13, 2021

Conversation

JedWatson
Copy link
Member

After feedback and an internal discussion, we're going to rename the resolveFields argument in the Items API to query.

Hopefully this helps make the Items API more intuitive and self-documenting.

For background, the Items API makes Keystone's GraphQL API available to Node.js directly, without the overhead of making a full GraphQL query over http. Because of the more direct syntax, you don't need to write out a full GraphQL query, but you do still need to nominate the fields you want resolved, in GraphQL syntax (the "field selection"). Unlike with most ORMs (which this provides a similar interface to) you get the full functionality of nested queries through relationships, and can use virtual fields.

It also offers a more direct option of returning the raw data from the database (effectively equivalent to select * in SQL) which we refer to as the "unresolved list item". This is required for certain back-end functionality to to work, e.g comparing a password hash (which is never available through the GraphQL API).

The challenge is given an API that can return two significantly different types, how do we make it intuitive to use? Hopefully naming the argument that controls this behaviour query makes it clearer:

(A) By default, the API will just return the id of each result

(B) If you want to query more fields (including virtual fields or related items) you pass the query: 'fields' argument, with GraphQL Query syntax for the fields you want to query from the graph

(C) If you want the raw / unresolved list item data, you pass query: false which bypasses the field resolvers

@changeset-bot
Copy link

changeset-bot bot commented Apr 13, 2021

🦋 Changeset detected

Latest commit: 72fb99c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@keystone-next/api-tests-legacy Patch
@keystone-next/example-ecommerce Patch
@keystone-next/example-next-lite Patch
@keystone-next/admin-ui Patch
@keystone-next/auth Major
@keystone-next/keystone Minor
@keystone-next/types Minor
@keystone-next/website Patch
@keystone-next/test-utils-legacy Patch
@keystone-next/example-auth Patch
@keystone-next/app-basic Patch
keystone-next-app Patch
@keystone-next/example-roles Patch
@keystone-next/example-sandbox Patch
@keystone-next/example-todo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Apr 13, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/EtkzAbUZEmviH9tE3gpXdqmZnMb4
✅ Preview: https://keystone-next-docs-git-rename-resolvefields-to-query-keystonejs.vercel.app

@vercel vercel bot temporarily deployed to Preview April 13, 2021 03:45 Inactive
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 13, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 72fb99c:

Sandbox Source
@keystone-next/example-sandbox Configuration

@vercel vercel bot temporarily deployed to Preview April 13, 2021 03:47 Inactive
@vercel vercel bot temporarily deployed to Preview April 13, 2021 04:40 Inactive
@vercel vercel bot temporarily deployed to Preview April 13, 2021 05:52 Inactive
@JedWatson JedWatson enabled auto-merge (squash) April 13, 2021 05:52
@JedWatson JedWatson merged commit 9e060fe into master Apr 13, 2021
@JedWatson JedWatson deleted the rename-resolvefields-to-query branch April 13, 2021 05:58
}
if (query !== undefined) return query;
if (resolveFields !== undefined) return resolveFields;
return 'id';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have defaulted it to false

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

Successfully merging this pull request may close these issues.

3 participants