diff --git a/packages/core/src/graphql/middleware.test.ts b/packages/core/src/graphql/middleware.test.ts index 08e37c63e..6d56d55de 100644 --- a/packages/core/src/graphql/middleware.test.ts +++ b/packages/core/src/graphql/middleware.test.ts @@ -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) => ({ diff --git a/packages/core/src/graphql/middleware.ts b/packages/core/src/graphql/middleware.ts index dba920d00..7ef7d4732 100644 --- a/packages/core/src/graphql/middleware.ts +++ b/packages/core/src/graphql/middleware.ts @@ -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 });