graphql/yoga-server/docs/integrations/integration-with-bun #2644
Replies: 7 comments 7 replies
-
How would I use websocket with |
Beta Was this translation helpful? Give feedback.
-
That s schema first, so how make code first ? |
Beta Was this translation helpful? Give feedback.
-
is supported jsonwebtoken in bun? https://the-guild.dev/graphql/yoga-server/docs/features/jwt if (!secretOrPrivateKey && options.algorithm !== 'none') { if (secretOrPrivateKey != null && !(secretOrPrivateKey instanceof KeyObject)) { |
Beta Was this translation helpful? Give feedback.
-
to anyone struggling with "subscription", here is the gist that helped me: key points to note/implement are: import { makeHandler } from "graphql-ws/lib/use/bun"; const websocketHandler = makeHandler({
|
Beta Was this translation helpful? Give feedback.
-
if you get the Typescript Issue Typescript type mismatch: Argument of type 'YogaServerInstance<{}, {}>' is not assignable to parameter of type 'Serve' using const server = Bun.serve({
fetch: yoga
}) with const server = Bun.serve({
fetch: (request) => yoga(request),
}) see #3003 (comment) |
Beta Was this translation helpful? Give feedback.
-
[email protected] is throwing a type error with [email protected] for this tutorial: const server = Bun.serve({
fetch: yoga,
});
|
Beta Was this translation helpful? Give feedback.
-
This implementation works with bun and yoga v5 import { makeHandler } from 'graphql-ws/use/bun';
import { createYoga } from 'graphql-yoga';
const yogaApp = createYoga({ ... config here... })
const bunServer = Bun.serve({
port: PORT,
hostname: '0.0.0.0',
websocket: makeHandler<{ token: string }, { user: UserSession.DefaultTokenPayload }>({
// extra is available here so we don't have to revalidate the JWT
context: setWebhookContext,
// return false or throw to prevent connection
async onConnect({ connectionParams, extra }) {
const token = connectionParams?.token;
if (typeof token !== 'string') return false;
try {
extra.user = authenticateJWT(token);
return true;
} catch {
return false;
}
},
schema: executableSchema,
}),
async fetch(request, server) {
const url = new URL(request.url);
switch (url.pathname) {
case '/health': {
return new Response('OK', { status: 200 });
}
case '/subscriptions': {
if (server.upgrade(request)) {
return new Response('OK', { status: 200 });
}
return new Response('Unable to upgrade to websockets', { status: 400 });
}
case yogaApp.graphqlEndpoint: {
return yogaApp.fetch(request, server);
}
... etc
}
},
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
graphql/yoga-server/docs/integrations/integration-with-bun
GraphQL Yoga provides you a cross-platform GraphQL Server. So you can easily integrate it into any platform besides Node.js.
https://the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-bun
Beta Was this translation helpful? Give feedback.
All reactions