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

Take LoadingType object union into account for FragmentStore #1389

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/sour-starfishes-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'houdini': minor
'houdini-svelte': patch
'houdini-react': patch
---

Add new types GraphQLLoadedValue and GraphQLLoadedObject, and include LoadingType in GraphQLValue
4 changes: 2 additions & 2 deletions packages/houdini-react/src/runtime/componentFields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defaultComponentField, type Cache } from '$houdini/runtime/cache/cache'
import { getFieldsForType } from '$houdini/runtime/lib/selection'
import type { DocumentArtifact, GraphQLValue } from 'houdini'
import type { DocumentArtifact, GraphQLLoadedValue, GraphQLValue } from 'houdini'

export function injectComponents({
cache,
Expand All @@ -12,7 +12,7 @@ export function injectComponents({
cache: Cache
selection: DocumentArtifact['selection']
data: GraphQLValue | null
variables: Record<string, GraphQLValue> | undefined | null
variables: Record<string, GraphQLLoadedValue> | undefined | null
parentType?: string
}) {
// if the value is null, we're done
Expand Down
8 changes: 6 additions & 2 deletions packages/houdini-react/src/runtime/hooks/useDocumentStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { DocumentArtifact, GraphQLVariables, QueryResult } from '$houdini/lib/types'
import type {
DocumentArtifact,
GraphQLVariables,
QueryResult,
GraphQLObject,
} from '$houdini/lib/types'
import type { DocumentStore, ObserveParams } from '$houdini/runtime/client'
import type { GraphQLObject } from 'houdini'
import * as React from 'react'

import { useClient } from '../routing'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { DocumentArtifact, GraphQLVariables, QueryResult } from '$houdini/lib/types'
import type {
DocumentArtifact,
GraphQLObject,
GraphQLVariables,
QueryResult,
} from '$houdini/lib/types'
import type { DocumentStore, SendParams } from '$houdini/runtime/client'
import type { GraphQLObject } from 'houdini'

import { useSession } from '../routing/Router'
import useDeepCompareEffect from './useDeepCompareEffect'
Expand Down
4 changes: 2 additions & 2 deletions packages/houdini-svelte/src/runtime/stores/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type {
GraphQLLoadedObject,
GraphQLVariables,
QueryResult,
SubscriptionArtifact,
} from '$houdini/runtime/lib/types'
import { CompiledSubscriptionKind } from '$houdini/runtime/lib/types'
import type { GraphQLObject } from 'houdini'
import { derived, writable, type Subscriber, type Writable } from 'svelte/store'

import { initClient } from '../client'
import { getSession } from '../session'
import { BaseStore } from './base'

export class SubscriptionStore<
_Data extends GraphQLObject,
_Data extends GraphQLLoadedObject,
_Input extends GraphQLVariables
> extends BaseStore<_Data, _Input, SubscriptionArtifact> {
kind = CompiledSubscriptionKind
Expand Down
10 changes: 6 additions & 4 deletions packages/houdini/src/runtime/cache/cache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { computeKey, PendingValue } from '../lib'
import type { ConfigFile } from '../lib/config'
import { computeID, defaultConfigValues, keyFieldsForType, getCurrentConfig } from '../lib/config'
import { computeID, defaultConfigValues, getCurrentConfig, keyFieldsForType } from '../lib/config'
import { deepEquals } from '../lib/deepEquals'
import { flatten } from '../lib/flatten'
import { getFieldsForType } from '../lib/selection'
import type {
GraphQLLoadedObject,
GraphQLLoadedValue,
GraphQLObject,
GraphQLValue,
NestedList,
Expand Down Expand Up @@ -1535,7 +1537,7 @@ class CacheInternal {
}
}

export function evaluateVariables(variables: ValueMap, args: GraphQLObject) {
export function evaluateVariables(variables: ValueMap, args: GraphQLLoadedObject) {
return Object.fromEntries(
Object.entries(variables).map(([key, value]) => [key, variableValue(value, args)])
)
Expand All @@ -1548,7 +1550,7 @@ function wrapInLists<T>(target: T, count: number = 0): T | NestedList<T> {
return wrapInLists([target], count - 1)
}

export function variableValue(value: ValueNode, args: GraphQLObject): GraphQLValue {
export function variableValue(value: ValueNode, args: GraphQLLoadedObject): GraphQLLoadedValue {
if (value.kind === 'StringValue') {
return value.value
}
Expand Down Expand Up @@ -1607,7 +1609,7 @@ export function defaultComponentField({
cache: Cache
component: Required<Required<SubscriptionSelection>['fields'][string]>['component']
loading?: boolean
variables: Record<string, GraphQLValue> | undefined | null
variables: Record<string, GraphQLLoadedValue> | undefined | null
parent: string
}) {
return (props: any) => {
Expand Down
19 changes: 18 additions & 1 deletion packages/houdini/src/runtime/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,26 @@ export type MutationOperation = {

export type GraphQLObject = { [key: string]: GraphQLValue }

export type GraphQLLoadedObject = {
[key: string]: GraphQLLoadedValue
}

export type GraphQLDefaultScalar = string | number | boolean

export type GraphQLValue = GraphQLDefaultScalar | null | GraphQLObject | GraphQLValue[] | undefined
export type GraphQLLoadedValue =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe i'm missing something but is there a problem with just updating GraphQLObject to always have the loaded value? If so, let's merge these 2 types with something like type GraphQLLoadedValue = GraphQLValue | LoadingType. Also, reading this outloud I think i would prefer a name like GraphQLValueWithLoading. a "loaded graphql value" sounds like it's already loaded (ie no loading values would be present).

| GraphQLDefaultScalar
| null
| GraphQLLoadedObject
| GraphQLLoadedValue[]
| undefined

export type GraphQLValue =
| LoadingType
| GraphQLDefaultScalar
| null
| GraphQLObject
| GraphQLValue[]
| undefined

export type GraphQLVariables = { [key: string]: any } | null

Expand Down
Loading