Skip to content

Commit

Permalink
fix graphql middleware issue
Browse files Browse the repository at this point in the history
  • Loading branch information
typedarray committed Jan 16, 2025
1 parent 59fbfa0 commit 296f1bd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/core/src/graphql/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,44 @@ test("middleware serves request", async (context) => {
await cleanup();
});

test("middleware supports path other than /graphql using hono routing", async (context) => {
const schema = {
table: onchainTable("table", (t) => ({ id: t.text().primaryKey() })),
};

const { database, indexingStore, cleanup } = await setupDatabaseServices(
context,
{ schema },
);

await indexingStore.insert(schema.table).values({
id: "0",
});

const app = new Hono().use(
"/not-graphql/**",
graphql({ schema, db: database.qb.drizzleReadonly }),
);

const response = await app.request("/not-graphql/at-all", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query { table(id: "0") { id } }`,
}),
});

expect(response.status).toBe(200);

expect(await response.json()).toMatchObject({
data: { table: { id: "0" } },
});

await cleanup();
});

test("middleware throws error when extra filter is applied", async (context) => {
const schema = {
table: onchainTable("table", (t) => ({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/graphql/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const graphql = (
generateSchema({ graphqlSchema }).catch(() => {});

const yoga = createYoga({
graphqlEndpoint: "*", // Disable built-in route validation, use Hono routing instead
schema: graphqlSchema,
context: () => {
const getDataLoader = buildDataLoaderCache({ drizzle: db });
Expand Down

0 comments on commit 296f1bd

Please sign in to comment.