Skip to content

Commit d5eeb6d

Browse files
committed
Add suggestString to Query
1 parent 0f267ae commit d5eeb6d

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

api/graphql/context.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ServerContext } from "@fab/runtime";
2+
import { ContextValueMaker } from "@glenstack/cf-workers-graphql";
3+
4+
export type Context = {
5+
version: string;
6+
};
7+
8+
export const makeContextValueMaker = ({
9+
bundle_id,
10+
}: ServerContext): ContextValueMaker => async (
11+
request: Request
12+
): Promise<Context> => ({
13+
version: bundle_id,
14+
});

api/graphql/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { FABRuntime } from "@fab/core";
22
import { makeGraphQLHandler } from "@glenstack/cf-workers-graphql";
3+
import { makeContextValueMaker } from "./context";
34
import { schema } from "./schema/index";
45
import { voyager } from "./voyager";
56

6-
const graphQLHandler = makeGraphQLHandler(schema);
7+
export default function graphql({ Router, ServerContext }: FABRuntime) {
8+
const graphQLHandler = makeGraphQLHandler(schema, {
9+
makeContextValue: makeContextValueMaker(ServerContext),
10+
});
711

8-
export default function graphql({ Router }: FABRuntime) {
912
Router.on("/graphql", ({ request }) => graphQLHandler(request));
1013
Router.on(
1114
"/voyager",

api/graphql/schema/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
typeDefs as searchResultTypeDefs,
99
resolvers as searchResultResolvers,
1010
} from "./types/searchResult";
11+
import { typeDefs as suggestStringTypeDefs } from "./types/suggestString";
1112

1213
const typeDefs = gql`
1314
type Query {
@@ -29,6 +30,7 @@ export const schema = makeExecutableSchema({
2930
externalSourceTypeDefs,
3031
documentTypeDefs,
3132
searchResultTypeDefs,
33+
suggestStringTypeDefs,
3234
],
3335
resolvers: [resolvers, searchResultResolvers],
3436
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import gql from "graphql-tag";
2+
3+
export const typeDefs = gql`
4+
extend type Query {
5+
suggestString(queryString: String!): [String!]!
6+
}
7+
`;

fab.config.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
// allowing for many production-specific optimisations. See https://fab.dev/kb/production
2222
// Example setting:
2323
// API_URL: 'https://api.example.com/graphql'
24+
ENV: "production",
25+
},
26+
staging: {
27+
ENV: "staging",
2428
},
2529
},
2630
deploy: {

0 commit comments

Comments
 (0)