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

Subset GraphQL query selections #3196

Draft
wants to merge 7 commits into
base: reduce-dataloader-queries
Choose a base branch
from

Conversation

yndajas
Copy link
Member

@yndajas yndajas commented Mar 11, 2025

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

This application is owned by the publishing platform team. Please let us know in #govuk-publishing-platform when you raise any PRs.

Follow these steps if you are doing a Rails upgrade.

@yndajas yndajas changed the title Subset graphql query selections Subset GraphQL query selections Mar 11, 2025
@yndajas yndajas force-pushed the reduce-dataloader-queries branch from 7e7c61f to 50c28a4 Compare March 12, 2025 09:41
@mike3985 mike3985 force-pushed the reduce-dataloader-queries branch from 50c28a4 to 7894c42 Compare March 12, 2025 14:15
@yndajas yndajas force-pushed the reduce-dataloader-queries branch from 7894c42 to 70f046a Compare March 12, 2025 17:16
available_translations aren't normal links, they have their own resolver
method. `links_field` is for normal links and it defines a common
resolver method.
@yndajas yndajas force-pushed the subset-graphql-query-selections branch from 6fa3bc5 to 3802f49 Compare March 12, 2025 17:23
mike3985 and others added 6 commits March 12, 2025 17:24
We're working towards SELECTing a subset of an Edition's columns, plus
a subset of some JOINed associations' columns, too. Working with the
sets, arrays and hashes required to build a complex SELECT argument is
getting increasingly gross, so this object is intended to provide
a smaller and neater interface for doing that.

This also provides a constructor that converts the GraphQL query's
edition selections to database column names. We include a list of valid
database columns and a hash which maps GraphQL fields not in the list to
the database columns they rely on

Co-authored-by: Ynda Jas <yndajas@gmail.com>
We're hoping to speed up our GraphQL responses by reducing the amount of
data retrieved from the database. By design we already only send the
client the data they've requested, but until now that meant that we've
been fetching a lot of data from the database that we don't actually
make use of in serving the response to the client.
I originally named this variable that way because I was having trouble
remembering what a "link type" even is and what its significance might
be. We've been knee-deep in these Publishing API concepts for a couple
of months now and as a result both of those things have become second
nature and this variable name has become cumbersome.

(I'm not sure whether the naming for reverse_links_field was ever quite
accurate.)
Following on from the changes we made to the QueryType's database query
for the root edition, this change aims to speed up GraphQL queries
involving generic links by reducing the amount of data retrieved from
the database.

Co-authored-by: Ynda Jas <yndajas@gmail.com>
Just like the changes we've just made to the database queries for
linked-to-editions, this reduces the amount of data retrieved from the
database when resolving reverse-linked editions in an attempt to speed
up response times.

Co-authored-by: Ynda Jas <yndajas@gmail.com>
The idea with this change is to reduce the amount of data retrieved from
the database in an attempt to speed up the overall response time to the
GraphQL client.

So far we've implemented this optimisation for the root edition,
linked-to editions and reverse-linked editions. Here we're introducing
the change for the person's role_appointments/roles fields specific to
the ministers index type.

We've followed the patterns established in the previous implementations
with the big differences being mostly:
* the larger number of JOINs needed in this query because we're
  traversing 2 levels of links
* the convenience of only needing to handle link set links here because
  we know that those are the only types of links involved in linking the
  ministers index's person-role_appointments-roles

Because of the large number of JOINS, we've resorted to supplying SQL
strings in order to provide our own, hopefully clearer, join table
aliases as opposed to leaving that to Active Record to generate.
@yndajas yndajas force-pushed the subset-graphql-query-selections branch from 3802f49 to 1e9b1f6 Compare March 12, 2025 17:24
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.

2 participants