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
gwennlbh committed Nov 11, 2024
1 parent 7287f24 commit 59d390a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-starfishes-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': minor
---

Add new types GraphQLLoadedValue and GraphQLLoadedObject, and include LoadingType in GraphQLValue
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 59d390a

Please sign in to comment.