Skip to content

Commit

Permalink
Take LoadingType into account in types
Browse files Browse the repository at this point in the history
  • Loading branch information
ewen-lbh committed Nov 11, 2024
1 parent 7287f24 commit c9d3466
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/sour-starfishes-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'houdini': minor
'houdini-svelte': patch
---

Add new types GraphQLLoadedValue and GraphQLLoadedObject, and include LoadingType in GraphQLValue
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 =
| GraphQLDefaultScalar
| null
| GraphQLLoadedObject
| GraphQLLoadedValue[]
| undefined

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

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

Expand Down

0 comments on commit c9d3466

Please sign in to comment.