@cedarjs/web 7.0.0-canary.3236 → 7.0.0-canary.3240

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CedarApolloProvider.d.ts","sourceRoot":"","sources":["../../src/apollo/CedarApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAK5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAGnE,OAAO,oBAAoB,CAAA;AAE3B,YAAY,EACV,uBAAuB,EACvB,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,sBAAsB,CAAA;AAE7B,UAAU,KAAK;IACb,mBAAmB,CAAC,EAAE,uBAAuB,CAAA;IAC7C,SAAS,CAAC,EAAE,YAAY,EAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,wBAAgB,mBAAmB,CAAC,EAClC,mBAAmB,EACnB,SAAS,EACT,OAAmB,EACnB,QAAkB,EAClB,QAAQ,GACT,EAAE,KAAK,qBAqCP"}
1
+ {"version":3,"file":"CedarApolloProvider.d.ts","sourceRoot":"","sources":["../../src/apollo/CedarApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAK5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAInE,OAAO,oBAAoB,CAAA;AAE3B,YAAY,EACV,uBAAuB,EACvB,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,sBAAsB,CAAA;AAE7B,UAAU,KAAK;IACb,mBAAmB,CAAC,EAAE,uBAAuB,CAAA;IAC7C,SAAS,CAAC,EAAE,YAAY,EAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,wBAAgB,mBAAmB,CAAC,EAClC,mBAAmB,EACnB,SAAS,EACT,OAAmB,EACnB,QAAkB,EAClB,QAAQ,GACT,EAAE,KAAK,qBAqCP"}
@@ -4,6 +4,7 @@ import { useNoAuth } from "@cedarjs/auth";
4
4
  import { FetchConfigProvider } from "../components/FetchConfigProvider.js";
5
5
  import { ApolloProviderWithFetchConfig } from "./ApolloProviderWithFetchConfig.js";
6
6
  import { fragmentRegistry } from "./fragmentRegistry.js";
7
+ import { withParsedScalars } from "./parsedScalars.js";
7
8
  import "./typeOverrides.js";
8
9
  function CedarApolloProvider({
9
10
  graphQLClientConfig,
@@ -20,7 +21,7 @@ function CedarApolloProvider({
20
21
  return new InMemoryCache({
21
22
  fragments: fragmentRegistry,
22
23
  possibleTypes: cacheConfig?.possibleTypes,
23
- ...cacheConfig
24
+ ...withParsedScalars(cacheConfig)
24
25
  });
25
26
  };
26
27
  const cache = createCache().restore(globalThis?.__CEDAR__APOLLO_STATE ?? {});
@@ -0,0 +1,36 @@
1
+ import type { InMemoryCacheConfig } from '@apollo/client';
2
+ /**
3
+ * The cache config that `vite-plugin-cedar-parsed-scalars` builds from the
4
+ * project's GraphQL schema and the `graphql.parsedScalars` setting in
5
+ * `cedar.toml`, and puts on `globalThis.__CEDAR__PARSED_SCALARS`.
6
+ */
7
+ export interface ParsedScalarsCacheConfig {
8
+ /**
9
+ * The scalars to parse, and the type each is parsed into
10
+ */
11
+ scalars: Record<string, string>;
12
+ /**
13
+ * The fields that hold a parsed scalar
14
+ */
15
+ typePolicies: Record<string, {
16
+ fields: Record<string, {
17
+ scalar: string;
18
+ }>;
19
+ }>;
20
+ /**
21
+ * The input objects that hold a parsed scalar, directly or through another
22
+ * input object
23
+ */
24
+ inputObjects: Record<string, {
25
+ fields: Record<string, string>;
26
+ }>;
27
+ }
28
+ /**
29
+ * Adds the scalars in `graphql.parsedScalars` to the cache config, so that
30
+ * Apollo Client's cache parses them when it reads a response and serializes
31
+ * them in a query's variables. Anything the app configured for the same
32
+ * scalar, field or input object takes precedence. Returns the config as it is
33
+ * when no scalar is parsed.
34
+ */
35
+ export declare function withParsedScalars(cacheConfig?: InMemoryCacheConfig): InMemoryCacheConfig | undefined;
36
+ //# sourceMappingURL=parsedScalars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsedScalars.d.ts","sourceRoot":"","sources":["../../src/apollo/parsedScalars.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAgB,MAAM,gBAAgB,CAAA;AAEvE;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC,CAAA;IAC5E;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAA;CACjE;AAmFD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,CAAC,EAAE,mBAAmB,GAChC,mBAAmB,GAAG,SAAS,CAmDjC"}
@@ -0,0 +1,75 @@
1
+ import { Scalar } from "@apollo/client";
2
+ const SCALAR_TYPES = {
3
+ Date: new Scalar({
4
+ parse: (serialized) => new Date(serialized),
5
+ serialize: (parsed) => parsed.toISOString(),
6
+ is: (value) => value instanceof Date
7
+ })
8
+ };
9
+ function mergeFieldPolicies(typeName, generated, configured = {}) {
10
+ const fields = { ...configured };
11
+ for (const [name, policy] of Object.entries(generated)) {
12
+ const configuredPolicy = configured[name];
13
+ const hasReadOrMerge = typeof configuredPolicy === "function" || configuredPolicy?.read !== void 0 || configuredPolicy?.merge !== void 0;
14
+ if (hasReadOrMerge) {
15
+ throw new Error(
16
+ `${typeName}.${name} holds a parsed ${policy.scalar} scalar and has a \`read\` or \`merge\` field policy. Apollo Client drops a field policy's \`read\` and \`merge\` the moment \`scalar\` is also set on it, so they can\u2019t both apply. Move the \`read\`/\`merge\` logic to a different field, for example one backed by a \`@requires\`-style resolver, or stop parsing this scalar.`
17
+ );
18
+ }
19
+ fields[name] = {
20
+ ...policy,
21
+ ...configuredPolicy
22
+ };
23
+ }
24
+ return fields;
25
+ }
26
+ function mergeInputObjects(generated, configured = {}) {
27
+ const inputObjects = { ...configured };
28
+ for (const [name, { fields }] of Object.entries(generated)) {
29
+ inputObjects[name] = {
30
+ ...configured[name],
31
+ fields: { ...fields, ...configured[name]?.fields }
32
+ };
33
+ }
34
+ return inputObjects;
35
+ }
36
+ function withParsedScalars(cacheConfig) {
37
+ const parsed = globalThis.__CEDAR__PARSED_SCALARS;
38
+ if (!parsed) {
39
+ return cacheConfig;
40
+ }
41
+ const scalars = Object.fromEntries(
42
+ Object.entries(parsed.scalars).map(([name, type]) => {
43
+ const scalarType = SCALAR_TYPES[type];
44
+ if (!scalarType) {
45
+ throw new Error(
46
+ `Can't parse the ${name} scalar into ${JSON.stringify(type)}. Supported: ` + Object.keys(SCALAR_TYPES).map((supported) => JSON.stringify(supported)).join(", ")
47
+ );
48
+ }
49
+ return [name, scalarType];
50
+ })
51
+ );
52
+ const typePolicies = { ...cacheConfig?.typePolicies };
53
+ for (const [typeName, { fields }] of Object.entries(parsed.typePolicies)) {
54
+ typePolicies[typeName] = {
55
+ ...typePolicies[typeName],
56
+ fields: mergeFieldPolicies(
57
+ typeName,
58
+ fields,
59
+ typePolicies[typeName]?.fields
60
+ )
61
+ };
62
+ }
63
+ return {
64
+ ...cacheConfig,
65
+ scalars: { ...scalars, ...cacheConfig?.scalars },
66
+ typePolicies,
67
+ inputObjects: mergeInputObjects(
68
+ parsed.inputObjects,
69
+ cacheConfig?.inputObjects
70
+ )
71
+ };
72
+ }
73
+ export {
74
+ withParsedScalars
75
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../src/apollo/suspense.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqB,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,QAAQ,EACR,mBAAmB,EACnB,eAAe,EAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,UAAU,EAEX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAEL,aAAa,EAEd,MAAM,gCAAgC,CAAA;AAGvC,OAAO,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAa5C,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,YAAY,CAAA;AASnB,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAEzD,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,gBAAgB,CAAC,OAAO,EACxB,OAAO,GAAG,MAAM,CACjB,GAAG;IACF,K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ACV,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,GACnB,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,gBAAgB,CAAC,OAAO,EACxB,OAAO,GAAG,MAAM,CACjB,GAAG;IACF,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,uBAAuB,CAAA;IACrC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAA;IACjC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,wBAAwB,CAAA;CAC7C,CAAA;AAqHD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,iBAAiB,CAAC;IACxD,mBAAmB,CAAC,EAAE,uBAAuB,CAAA;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;IAC7C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAsCA,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB;0BAhDV,uBAAuB;cACnC,OAAO;eACN,UAAU,CAAC,OAAO,eAAe,CAAC;cACnC,KAAK,CAAC,SAAS;EA6C6B,CAAA"}
@@ -28,6 +28,7 @@ import {
28
28
  createTokenLink,
29
29
  createUpdateDataLink
30
30
  } from "./links.js";
31
+ import { withParsedScalars } from "./parsedScalars.js";
31
32
  const WrappedApolloProvider = WrapApolloProvider(
32
33
  buildManualDataTransport({
33
34
  useInsertHtml() {
@@ -101,7 +102,7 @@ const CedarApolloProvider = ({
101
102
  const createCache = () => {
102
103
  return new InMemoryCache({
103
104
  fragments: fragmentRegistry,
104
- ...cacheConfig
105
+ ...withParsedScalars(cacheConfig)
105
106
  });
106
107
  };
107
108
  const cache = createCache().restore(globalThis?.__CEDAR__APOLLO_STATE ?? {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/web",
3
- "version": "7.0.0-canary.3236",
3
+ "version": "7.0.0-canary.3240",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@apollo/client": "4.3.1",
82
- "@cedarjs/server-store": "7.0.0-canary.3236",
82
+ "@cedarjs/server-store": "7.0.0-canary.3240",
83
83
  "@dr.pogodin/react-helmet": "2.0.4",
84
84
  "@whatwg-node/fetch": "0.10.13",
85
85
  "apollo-upload-client": "19.0.0",
@@ -95,9 +95,9 @@
95
95
  "devDependencies": {
96
96
  "@apollo/client-react-streaming": "0.14.5",
97
97
  "@arethetypeswrong/cli": "0.18.5",
98
- "@cedarjs/auth": "7.0.0-canary.3236",
99
- "@cedarjs/framework-tools": "7.0.0-canary.3236",
100
- "@cedarjs/internal": "7.0.0-canary.3236",
98
+ "@cedarjs/auth": "7.0.0-canary.3240",
99
+ "@cedarjs/framework-tools": "7.0.0-canary.3240",
100
+ "@cedarjs/internal": "7.0.0-canary.3240",
101
101
  "@testing-library/dom": "10.4.2",
102
102
  "@testing-library/jest-dom": "6.9.1",
103
103
  "@testing-library/react": "16.3.3",
@@ -114,7 +114,7 @@
114
114
  "vitest": "4.1.11"
115
115
  },
116
116
  "peerDependencies": {
117
- "@cedarjs/auth": "7.0.0-canary.3236",
117
+ "@cedarjs/auth": "7.0.0-canary.3240",
118
118
  "react": "19.3.0",
119
119
  "react-dom": "19.3.0"
120
120
  },