houdini-core 2.0.0-next.20 → 2.0.0-next.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini-core",
3
- "version": "2.0.0-next.20",
3
+ "version": "2.0.0-next.22",
4
4
  "description": "The core GraphQL client for Houdini",
5
5
  "keywords": [
6
6
  "graphql",
@@ -21,13 +21,13 @@
21
21
  "minimatch": "^10.2.5"
22
22
  },
23
23
  "optionalDependencies": {
24
- "houdini-core-darwin-x64": "2.0.0-next.20",
25
- "houdini-core-darwin-arm64": "2.0.0-next.20",
26
- "houdini-core-linux-x64": "2.0.0-next.20",
27
- "houdini-core-linux-arm64": "2.0.0-next.20",
28
- "houdini-core-win32-x64": "2.0.0-next.20",
29
- "houdini-core-win32-arm64": "2.0.0-next.20",
30
- "houdini-core-wasm": "2.0.0-next.20"
24
+ "houdini-core-darwin-x64": "2.0.0-next.22",
25
+ "houdini-core-darwin-arm64": "2.0.0-next.22",
26
+ "houdini-core-linux-x64": "2.0.0-next.22",
27
+ "houdini-core-linux-arm64": "2.0.0-next.22",
28
+ "houdini-core-win32-x64": "2.0.0-next.22",
29
+ "houdini-core-win32-arm64": "2.0.0-next.22",
30
+ "houdini-core-wasm": "2.0.0-next.22"
31
31
  },
32
32
  "files": [
33
33
  "bin",
package/postInstall.js CHANGED
@@ -5,7 +5,7 @@ const https = require('https')
5
5
  const child_process = require('child_process')
6
6
 
7
7
  // Adjust the version you want to install. You can also make this dynamic.
8
- const BINARY_DISTRIBUTION_VERSION = '2.0.0-next.20'
8
+ const BINARY_DISTRIBUTION_VERSION = '2.0.0-next.22'
9
9
 
10
10
  // Windows binaries end with .exe so we need to special case them.
11
11
  const binaryName = process.platform === 'win32' ? 'houdini-core.exe' : 'houdini-core'
@@ -48,9 +48,16 @@ export const fragment = (cache: Cache) =>
48
48
  selection: ctx.artifact.selection,
49
49
  variables: () => variables,
50
50
  parentID: ctx.stuff.parentID,
51
- set: (newValue) => {
51
+ onMessage: (message) => {
52
+ // fragments can't issue network requests. refetch messages are
53
+ // handled by the query that owns this data — it holds its own
54
+ // masked parent subscription on the same records
55
+ if (message.kind !== 'update') {
56
+ return
57
+ }
58
+
52
59
  resolve(ctx, {
53
- data: newValue,
60
+ data: message.data,
54
61
  errors: null,
55
62
  fetching: false,
56
63
  partial: false,
@@ -1,6 +1,6 @@
1
1
  import type { RuntimeScalarPayload } from 'houdini'
2
2
  import type { Cache } from 'houdini/runtime/cache'
3
- import { type SubscriptionSpec, ArtifactKind, DataSource } from 'houdini/runtime/types'
3
+ import { type SubscriptionSpec, ArtifactKind, CachePolicy, DataSource } from 'houdini/runtime/types'
4
4
 
5
5
  import { documentPlugin } from './utils/index.js'
6
6
 
@@ -12,6 +12,11 @@ export const query = (cache: Cache) =>
12
12
  // remember the last variables we were called with
13
13
  let lastVariables: Record<string, any> | null = null
14
14
 
15
+ // track the most recent session so that refetch requests triggered by
16
+ // record.refresh() use the current auth token, not the one from when the
17
+ // subscription was first created
18
+ let lastSession: App.Session | null | undefined = null
19
+
15
20
  // the function to call when a query is sent
16
21
  return {
17
22
  start(ctx, { next }) {
@@ -46,6 +51,10 @@ export const query = (cache: Cache) =>
46
51
  // patch subscriptions on the way out so that we don't get a cache update
47
52
  // before the promise resolves
48
53
  end(ctx, { resolve, marshalVariables, variablesChanged }) {
54
+ // always keep the session current so that a later record.refresh() call
55
+ // uses the auth token from the most recent send(), not from subscription time
56
+ lastSession = ctx.session
57
+
49
58
  // if the variables have changed we need to setup a new subscription with the cache
50
59
  if (variablesChanged(ctx) && !ctx.cacheParams?.disableSubscriptions) {
51
60
  // if the variables changed we need to unsubscribe from the old fields and
@@ -63,9 +72,20 @@ export const query = (cache: Cache) =>
63
72
  rootType: ctx.artifact.rootType,
64
73
  selection: ctx.artifact.selection,
65
74
  variables: () => variables,
66
- set: (newValue) => {
75
+ onMessage: (message) => {
76
+ // if the cache asked us to refetch, kick off a brand new request
77
+ // through the full pipeline so the document reloads from the API
78
+ if (message.kind === 'refetch') {
79
+ ctx.documentStore.send({
80
+ policy: CachePolicy.NetworkOnly,
81
+ session: lastSession,
82
+ metadata: ctx.metadata,
83
+ })
84
+ return
85
+ }
86
+
67
87
  resolve(ctx, {
68
- data: newValue,
88
+ data: message.data,
69
89
  errors: null,
70
90
  fetching: false,
71
91
  partial: false,
@@ -1,6 +1,7 @@
1
1
  import { deepEquals } from 'houdini/runtime'
2
2
  import type { ClientPluginContext } from 'houdini/runtime/documentStore'
3
3
  import { ArtifactKind, DataSource } from 'houdini/runtime/types'
4
+ import type { GraphQLError } from 'houdini/runtime/types'
4
5
 
5
6
  import { documentPlugin } from './utils/index.js'
6
7
 
@@ -110,7 +111,7 @@ export type SubscriptionClient = {
110
111
  extensions?: Record<'persistedQuery', string> | Record<string, unknown>
111
112
  },
112
113
  handlers: {
113
- next: (payload: { data?: {} | null; errors?: readonly { message: string }[] }) => void
114
+ next: (payload: { data?: {} | null; errors?: readonly GraphQLError[] }) => void
114
115
  error: (data: {}) => void
115
116
  complete: () => void
116
117
  }
@@ -81,6 +81,19 @@ export class ListCollection<Def extends CacheTypeDef, ListName extends ValidList
81
81
  }
82
82
  }
83
83
 
84
+ upsert(where: 'first' | 'last', ...records: ListType<Def, ListName>[]) {
85
+ if (!this.#collection) {
86
+ return
87
+ }
88
+
89
+ const { selection, data } = this.#listOperationPayload(records)
90
+ for (const entry of data) {
91
+ if (entry) {
92
+ this.#collection.upsertInList(selection, entry, {}, where)
93
+ }
94
+ }
95
+ }
96
+
84
97
  when(filter: ListFilters<Def, ListName>): ListCollection<Def, ListName> {
85
98
  if (!this.#collection) {
86
99
  return this
@@ -94,6 +94,14 @@ export class Record<Def extends CacheTypeDef, Type extends ValidTypes<Def>> {
94
94
  this.#cache._internal_unstable.delete(this.#id)
95
95
  }
96
96
 
97
+ /**
98
+ * Ask every document whose data contains this record to refetch itself
99
+ * so the record's values are reloaded from the API.
100
+ */
101
+ refresh() {
102
+ this.#cache._internal_unstable.refresh(this.#id)
103
+ }
104
+
97
105
  /**
98
106
  * Mark some elements of the record stale in the cache.
99
107
  * @param field