From c9d34663c2a3cdd6e56ff1ae93f1c6b9fc016c24 Mon Sep 17 00:00:00 2001 From: Gwen Le Bihan Date: Mon, 11 Nov 2024 14:54:00 +0100 Subject: [PATCH 1/2] Take LoadingType into account in types --- .changeset/sour-starfishes-push.md | 6 ++++++ .../src/runtime/stores/subscription.ts | 4 ++-- packages/houdini/src/runtime/cache/cache.ts | 10 ++++++---- packages/houdini/src/runtime/lib/types.ts | 19 ++++++++++++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 .changeset/sour-starfishes-push.md diff --git a/.changeset/sour-starfishes-push.md b/.changeset/sour-starfishes-push.md new file mode 100644 index 0000000000..626ffe5a48 --- /dev/null +++ b/.changeset/sour-starfishes-push.md @@ -0,0 +1,6 @@ +--- +'houdini': minor +'houdini-svelte': patch +--- + +Add new types GraphQLLoadedValue and GraphQLLoadedObject, and include LoadingType in GraphQLValue diff --git a/packages/houdini-svelte/src/runtime/stores/subscription.ts b/packages/houdini-svelte/src/runtime/stores/subscription.ts index 8cecec6eb9..d5aa0b94e6 100644 --- a/packages/houdini-svelte/src/runtime/stores/subscription.ts +++ b/packages/houdini-svelte/src/runtime/stores/subscription.ts @@ -1,10 +1,10 @@ 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' @@ -12,7 +12,7 @@ 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 diff --git a/packages/houdini/src/runtime/cache/cache.ts b/packages/houdini/src/runtime/cache/cache.ts index 581314933b..56c602516f 100644 --- a/packages/houdini/src/runtime/cache/cache.ts +++ b/packages/houdini/src/runtime/cache/cache.ts @@ -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, @@ -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)]) ) @@ -1548,7 +1550,7 @@ function wrapInLists(target: T, count: number = 0): T | NestedList { 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 } @@ -1607,7 +1609,7 @@ export function defaultComponentField({ cache: Cache component: Required['fields'][string]>['component'] loading?: boolean - variables: Record | undefined | null + variables: Record | undefined | null parent: string }) { return (props: any) => { diff --git a/packages/houdini/src/runtime/lib/types.ts b/packages/houdini/src/runtime/lib/types.ts index d4ced0ccf0..b0d73855bc 100644 --- a/packages/houdini/src/runtime/lib/types.ts +++ b/packages/houdini/src/runtime/lib/types.ts @@ -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 = + | GraphQLDefaultScalar + | null + | GraphQLLoadedObject + | GraphQLLoadedValue[] + | undefined + +export type GraphQLValue = + | LoadingType + | GraphQLDefaultScalar + | null + | GraphQLObject + | GraphQLValue[] + | undefined export type GraphQLVariables = { [key: string]: any } | null From b846ed9b660c0f9bc3a4de48e2db790857310235 Mon Sep 17 00:00:00 2001 From: Gwen Le Bihan Date: Mon, 11 Nov 2024 15:07:29 +0100 Subject: [PATCH 2/2] Update react types --- .changeset/sour-starfishes-push.md | 1 + packages/houdini-react/src/runtime/componentFields.ts | 4 ++-- .../houdini-react/src/runtime/hooks/useDocumentStore.ts | 8 ++++++-- .../src/runtime/hooks/useDocumentSubscription.ts | 8 ++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.changeset/sour-starfishes-push.md b/.changeset/sour-starfishes-push.md index 626ffe5a48..5fa3b9ad9e 100644 --- a/.changeset/sour-starfishes-push.md +++ b/.changeset/sour-starfishes-push.md @@ -1,6 +1,7 @@ --- 'houdini': minor 'houdini-svelte': patch +'houdini-react': patch --- Add new types GraphQLLoadedValue and GraphQLLoadedObject, and include LoadingType in GraphQLValue diff --git a/packages/houdini-react/src/runtime/componentFields.ts b/packages/houdini-react/src/runtime/componentFields.ts index 53a17f327c..fafec75177 100644 --- a/packages/houdini-react/src/runtime/componentFields.ts +++ b/packages/houdini-react/src/runtime/componentFields.ts @@ -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, @@ -12,7 +12,7 @@ export function injectComponents({ cache: Cache selection: DocumentArtifact['selection'] data: GraphQLValue | null - variables: Record | undefined | null + variables: Record | undefined | null parentType?: string }) { // if the value is null, we're done diff --git a/packages/houdini-react/src/runtime/hooks/useDocumentStore.ts b/packages/houdini-react/src/runtime/hooks/useDocumentStore.ts index 13be07d7f9..9603ae8a3d 100644 --- a/packages/houdini-react/src/runtime/hooks/useDocumentStore.ts +++ b/packages/houdini-react/src/runtime/hooks/useDocumentStore.ts @@ -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' diff --git a/packages/houdini-react/src/runtime/hooks/useDocumentSubscription.ts b/packages/houdini-react/src/runtime/hooks/useDocumentSubscription.ts index 4c78e6f282..0d0b1ad9b2 100644 --- a/packages/houdini-react/src/runtime/hooks/useDocumentSubscription.ts +++ b/packages/houdini-react/src/runtime/hooks/useDocumentSubscription.ts @@ -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'