@apollo/client-ai-apps 0.5.2 → 0.5.4
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/CHANGELOG.md +39 -0
- package/dist/core/ApolloClient.d.ts +1 -1
- package/dist/core/ApolloClient.d.ts.map +1 -1
- package/dist/core/ApolloClient.js +1 -1
- package/dist/core/ApolloClient.js.map +1 -1
- package/dist/mcp/core/ApolloClient.d.ts +6 -1
- package/dist/mcp/core/ApolloClient.d.ts.map +1 -1
- package/dist/mcp/core/ApolloClient.js +36 -3
- package/dist/mcp/core/ApolloClient.js.map +1 -1
- package/dist/mcp/core/McpAppManager.d.ts +2 -2
- package/dist/mcp/core/McpAppManager.d.ts.map +1 -1
- package/dist/mcp/core/McpAppManager.js +3 -3
- package/dist/mcp/core/McpAppManager.js.map +1 -1
- package/dist/mcp/react/hooks/createHydrationUtils.d.ts +15 -0
- package/dist/mcp/react/hooks/createHydrationUtils.d.ts.map +1 -0
- package/dist/mcp/react/hooks/createHydrationUtils.js +113 -0
- package/dist/mcp/react/hooks/createHydrationUtils.js.map +1 -0
- package/dist/mcp/react/index.d.ts +1 -0
- package/dist/mcp/react/index.d.ts.map +1 -1
- package/dist/mcp/react/index.js +1 -0
- package/dist/mcp/react/index.js.map +1 -1
- package/dist/openai/core/ApolloClient.d.ts +6 -1
- package/dist/openai/core/ApolloClient.d.ts.map +1 -1
- package/dist/openai/core/ApolloClient.js +37 -3
- package/dist/openai/core/ApolloClient.js.map +1 -1
- package/dist/openai/core/McpAppManager.d.ts +2 -2
- package/dist/openai/core/McpAppManager.d.ts.map +1 -1
- package/dist/openai/core/McpAppManager.js +5 -5
- package/dist/openai/core/McpAppManager.js.map +1 -1
- package/dist/openai/react/hooks/createHydrationUtils.d.ts +15 -0
- package/dist/openai/react/hooks/createHydrationUtils.d.ts.map +1 -0
- package/dist/openai/react/hooks/createHydrationUtils.js +113 -0
- package/dist/openai/react/hooks/createHydrationUtils.js.map +1 -0
- package/dist/openai/react/index.d.ts +1 -0
- package/dist/openai/react/index.d.ts.map +1 -1
- package/dist/openai/react/index.js +1 -0
- package/dist/openai/react/index.js.map +1 -1
- package/dist/react/ApolloProvider.js +1 -1
- package/dist/react/ApolloProvider.js.map +1 -1
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +3 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mcp.d.ts +1 -1
- package/dist/react/index.mcp.d.ts.map +1 -1
- package/dist/react/index.mcp.js +1 -1
- package/dist/react/index.mcp.js.map +1 -1
- package/dist/react/index.openai.d.ts +1 -1
- package/dist/react/index.openai.d.ts.map +1 -1
- package/dist/react/index.openai.js +1 -1
- package/dist/react/index.openai.js.map +1 -1
- package/dist/react/reactive.d.ts +9 -0
- package/dist/react/reactive.d.ts.map +1 -0
- package/dist/react/reactive.js +11 -0
- package/dist/react/reactive.js.map +1 -0
- package/dist/utilities/getToolNamesFromDocument.d.ts +3 -0
- package/dist/utilities/getToolNamesFromDocument.d.ts.map +1 -0
- package/dist/utilities/getToolNamesFromDocument.js +12 -0
- package/dist/utilities/getToolNamesFromDocument.js.map +1 -0
- package/dist/utilities/getVariableNamesFromDocument.d.ts +3 -0
- package/dist/utilities/getVariableNamesFromDocument.d.ts.map +1 -0
- package/dist/utilities/getVariableNamesFromDocument.js +6 -0
- package/dist/utilities/getVariableNamesFromDocument.js.map +1 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +3 -0
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/warnOnVariableMismatch.d.ts +3 -0
- package/dist/utilities/warnOnVariableMismatch.d.ts.map +1 -0
- package/dist/utilities/warnOnVariableMismatch.js +10 -0
- package/dist/utilities/warnOnVariableMismatch.js.map +1 -0
- package/dist/vite/apolloClientAiApps.d.ts.map +1 -1
- package/dist/vite/apolloClientAiApps.js +35 -31
- package/dist/vite/apolloClientAiApps.js.map +1 -1
- package/package.json +2 -1
- package/src/core/ApolloClient.ts +1 -1
- package/src/mcp/core/ApolloClient.ts +67 -2
- package/src/mcp/core/McpAppManager.ts +3 -3
- package/src/mcp/core/__tests__/ApolloClient.test.ts +109 -6
- package/src/mcp/link/__tests__/ToolCallLink.test.ts +1 -1
- package/src/mcp/react/hooks/__tests__/createHydrationUtils.test.tsx +1228 -0
- package/src/mcp/react/hooks/createHydrationUtils.ts +182 -0
- package/src/mcp/react/index.ts +1 -0
- package/src/openai/core/ApolloClient.ts +68 -2
- package/src/openai/core/McpAppManager.ts +5 -5
- package/src/openai/core/__tests__/ApolloClient.test.ts +113 -7
- package/src/openai/react/hooks/__tests__/createHydrationUtils.test.tsx +1333 -0
- package/src/openai/react/hooks/createHydrationUtils.ts +182 -0
- package/src/openai/react/index.ts +1 -0
- package/src/react/ApolloProvider.tsx +1 -1
- package/src/react/index.mcp.ts +1 -0
- package/src/react/index.openai.ts +1 -0
- package/src/react/index.ts +7 -0
- package/src/react/reactive.ts +19 -0
- package/src/testing/internal/mcp/graphqlToolResult.ts +5 -5
- package/src/utilities/getToolNamesFromDocument.ts +15 -0
- package/src/utilities/getVariableNamesFromDocument.ts +9 -0
- package/src/utilities/index.ts +3 -0
- package/src/utilities/warnOnVariableMismatch.ts +20 -0
- package/src/vite/__tests__/apolloClientAiApps.test.ts +183 -2
- package/src/vite/apolloClientAiApps.ts +46 -40
|
@@ -14,7 +14,7 @@ import { glob } from "glob";
|
|
|
14
14
|
import { print } from "@apollo/client/utilities";
|
|
15
15
|
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
16
16
|
import { of } from "rxjs";
|
|
17
|
-
import { Kind,
|
|
17
|
+
import { Kind, OperationTypeNode, parse } from "graphql";
|
|
18
18
|
import {
|
|
19
19
|
getArgumentValue,
|
|
20
20
|
getDirectiveArgument,
|
|
@@ -30,6 +30,7 @@ import { explorer } from "./utilities/config.js";
|
|
|
30
30
|
import type { ApolloClientAiAppsConfig } from "../config/index.js";
|
|
31
31
|
import { ApolloClientAiAppsConfigSchema } from "../config/schema.js";
|
|
32
32
|
import { z } from "zod";
|
|
33
|
+
import { createFragmentRegistry } from "@apollo/client/cache";
|
|
33
34
|
|
|
34
35
|
export declare namespace apolloClientAiApps {
|
|
35
36
|
export type Target = ApolloClientAiAppsConfig.AppTarget;
|
|
@@ -66,7 +67,7 @@ export function devTarget(target: string | undefined) {
|
|
|
66
67
|
interface FileCache {
|
|
67
68
|
file: string;
|
|
68
69
|
hash: string;
|
|
69
|
-
|
|
70
|
+
sources: DocumentNode[];
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
export function apolloClientAiApps(
|
|
@@ -79,6 +80,8 @@ export function apolloClientAiApps(
|
|
|
79
80
|
let packageJson!: Record<string, any>;
|
|
80
81
|
let config!: ResolvedConfig;
|
|
81
82
|
|
|
83
|
+
const fragments = createFragmentRegistry();
|
|
84
|
+
|
|
82
85
|
invariant(
|
|
83
86
|
Array.isArray(targets) && targets.length > 0,
|
|
84
87
|
"The `targets` option must be a non-empty array"
|
|
@@ -90,7 +93,7 @@ export function apolloClientAiApps(
|
|
|
90
93
|
);
|
|
91
94
|
|
|
92
95
|
const client = new ApolloClient({
|
|
93
|
-
cache: new InMemoryCache(),
|
|
96
|
+
cache: new InMemoryCache({ fragments }),
|
|
94
97
|
link: processQueryLink,
|
|
95
98
|
});
|
|
96
99
|
|
|
@@ -106,52 +109,57 @@ export function apolloClientAiApps(
|
|
|
106
109
|
{ name: "graphql-tag", identifier: "gql" },
|
|
107
110
|
{ name: "@apollo/client", identifier: "gql" },
|
|
108
111
|
],
|
|
109
|
-
}).map((source) => (
|
|
110
|
-
node: parse(source.body),
|
|
111
|
-
file,
|
|
112
|
-
location: source.locationOffset,
|
|
113
|
-
}));
|
|
112
|
+
}).map((source) => parse(source.body));
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
for (const source of sources) {
|
|
117
|
-
const type = (
|
|
118
|
-
source.node.definitions.find(
|
|
119
|
-
(d) => d.kind === "OperationDefinition"
|
|
120
|
-
) as OperationDefinitionNode
|
|
121
|
-
).operation;
|
|
122
|
-
|
|
123
|
-
let result;
|
|
124
|
-
if (type === "query") {
|
|
125
|
-
result = await client.query({
|
|
126
|
-
query: source.node,
|
|
127
|
-
fetchPolicy: "no-cache",
|
|
128
|
-
});
|
|
129
|
-
} else if (type === "mutation") {
|
|
130
|
-
result = await client.mutate({
|
|
131
|
-
mutation: source.node,
|
|
132
|
-
fetchPolicy: "no-cache",
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
throw new Error(
|
|
136
|
-
"Found an unsupported operation type. Only Query and Mutation are supported."
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
operations.push(result.data as ManifestOperation);
|
|
140
|
-
}
|
|
114
|
+
fragments.register(...sources);
|
|
141
115
|
|
|
142
116
|
cache.set(file, {
|
|
143
117
|
file: file,
|
|
144
118
|
hash: fileHash,
|
|
145
|
-
|
|
119
|
+
sources,
|
|
146
120
|
});
|
|
147
121
|
}
|
|
148
122
|
|
|
149
123
|
async function generateManifest(environment?: Environment) {
|
|
150
124
|
const appsConfig = await getAppsConfig();
|
|
151
|
-
const
|
|
152
|
-
(entry) => entry.
|
|
125
|
+
const sources = Array.from(cache.values()).flatMap(
|
|
126
|
+
(entry) => entry.sources
|
|
153
127
|
);
|
|
154
128
|
|
|
129
|
+
const operations: ManifestOperation[] = [];
|
|
130
|
+
for (const source of sources) {
|
|
131
|
+
const operationDef = source.definitions.find(
|
|
132
|
+
(d) => d.kind === Kind.OPERATION_DEFINITION
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (!operationDef) continue;
|
|
136
|
+
|
|
137
|
+
switch (operationDef.operation) {
|
|
138
|
+
case OperationTypeNode.QUERY: {
|
|
139
|
+
const result = await client.query<ManifestOperation>({
|
|
140
|
+
query: source,
|
|
141
|
+
fetchPolicy: "no-cache",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
operations.push(result.data!);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case OperationTypeNode.MUTATION: {
|
|
148
|
+
const result = await client.mutate<ManifestOperation>({
|
|
149
|
+
mutation: source,
|
|
150
|
+
fetchPolicy: "no-cache",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
operations.push(result.data!);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default:
|
|
157
|
+
throw new Error(
|
|
158
|
+
`Found unsupported operation type '${operationDef.operation}'. Only queries and mutations are supported.`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
155
163
|
invariant(
|
|
156
164
|
operations.filter((o) => o.prefetch).length <= 1,
|
|
157
165
|
"Found multiple operations marked as `@prefetch`. You can only mark 1 operation with `@prefetch`."
|
|
@@ -192,9 +200,7 @@ export function apolloClientAiApps(
|
|
|
192
200
|
name: appsConfig.name ?? packageJson.name,
|
|
193
201
|
description: appsConfig.description ?? packageJson.description,
|
|
194
202
|
hash: createHash("sha256").update(Date.now().toString()).digest("hex"),
|
|
195
|
-
operations
|
|
196
|
-
(entry) => entry.operations
|
|
197
|
-
),
|
|
203
|
+
operations,
|
|
198
204
|
resource,
|
|
199
205
|
csp: {
|
|
200
206
|
connectDomains: appsConfig.csp?.connectDomains ?? [],
|