Carbon-Farm-Network / app-carbon-farm-network

GNU Affero General Public License v3.0
2 stars 0 forks source link

GraphQL query cleanup / simplification pass #22

Open pospi opened 1 year ago

pospi commented 1 year ago

Many components (resource_specifications/+page.svelte as an example) have multiple query() bindings in them which could be combined into a singular query() which requests all dependent data in its entirety. In the case of this example, resourceSpecifications and GetUnits could be combined by simply listing them one after the other inside a single query {} block.

We should check over the codebase for these and merge as appropriate since it will simplify initialisation logic and lead to increased cache utilisation by the GraphQL query backend (ie. fewer calls to Holochain needed).

pospi commented 1 year ago

Also to note that in my testing the getCurrentResult() -> refetch() dance does not seem to be necessary.

If the component needs to run additional logic after a query has first executed, this should work fine:

const GET_UNITS = gql`/* ... */`
const getUnits: ReadableQuery<UnitsQueryResponse> = query(GET_UNITS)

onMount(async () => {
  const units = await getUnits.refetch()
  // do stuff with `units`
})