feat: Integrate asynchronous GraphQL context in Hono handler
This commit is contained in:
@@ -6,36 +6,36 @@ import { resolvers } from "./resolvers";
|
||||
import { typeDefs } from "./schema";
|
||||
|
||||
const schema = createSchema({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
typeDefs,
|
||||
resolvers,
|
||||
});
|
||||
|
||||
const yoga = createYoga({
|
||||
schema,
|
||||
graphqlEndpoint: "/graphql",
|
||||
landingPage: false, // Disable landing page for production
|
||||
graphiql: {
|
||||
title: "Aniplay GraphQL API",
|
||||
},
|
||||
context: ({ request }) => {
|
||||
// Extract Hono context from the request
|
||||
// graphql-yoga passes the raw request, but we need Hono context
|
||||
// This will be provided when we integrate with Hono
|
||||
return request as any;
|
||||
},
|
||||
schema,
|
||||
graphqlEndpoint: "/graphql",
|
||||
landingPage: false, // Disable landing page for production
|
||||
graphiql: {
|
||||
title: "Aniplay GraphQL API",
|
||||
},
|
||||
context: ({ request }) => {
|
||||
// Extract Hono context from the request
|
||||
// graphql-yoga passes the raw request, but we need Hono context
|
||||
// This will be provided when we integrate with Hono
|
||||
return request as any;
|
||||
},
|
||||
});
|
||||
|
||||
const app = new Hono<Cloudflare.Env>();
|
||||
|
||||
app.all("/", async (c) => {
|
||||
const graphqlContext = createGraphQLContext(c);
|
||||
const graphqlContext = await createGraphQLContext(c);
|
||||
|
||||
// Create a custom request object that includes our GraphQL context
|
||||
const request = c.req.raw.clone();
|
||||
(request as any).graphqlContext = graphqlContext;
|
||||
// Create a custom request object that includes our GraphQL context
|
||||
const request = c.req.raw.clone();
|
||||
(request as any).graphqlContext = graphqlContext;
|
||||
|
||||
const response = await yoga.fetch(request, graphqlContext);
|
||||
return response;
|
||||
const response = await yoga.fetch(request, graphqlContext);
|
||||
return response;
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
||||
Reference in New Issue
Block a user