elysiajs / elysia-apollo Goto Github PK
View Code? Open in Web Editor NEWPlugin for Elysia for using GraphQL Apollo
License: MIT License
Plugin for Elysia for using GraphQL Apollo
License: MIT License
GraphQL Mobius is a nice utility that provides LSP for GraphQL schema.
It is already implemented in Elysia plugin for GraphQL Yoga and it would be nice to have it in Apollo too.
Getting the below error when attempting batched http requests:
Invalid body, 'type': Expected object
Expected: {
"query": ""
}
Assuming the guard needs updating to accept an array if allowBatchedHttpRequests: true
When I run tsc
this file is incorrectly picked up even after explicitly setting skipLibCheck
and exclude
options on tsconfig.json
.
node_modules/@elysiajs/apollo/src/index.ts:65:41 - error TS2345: Argument of type 'string | (() => Promise<string>)' is not assignable to parameter of type 'ReadableStream<any> | BlobPart | BlobPart[] | FormData | URLSearchParams | null | undefined'.
Type '() => Promise<string>' is not assignable to type 'ReadableStream<any> | BlobPart | BlobPart[] | FormData | URLSearchParams | null | undefined'.
65 return new Response(landingPage, {
~~~~~~~~~~~
Found 1 error in node_modules/@elysiajs/apollo/src/index.ts:65
Even vscode picks it up!
Not sure if this is an Elysia issue, bun or a plugin issue, but sometimes this plugin just stops working
I am currently using bun 1.0.15 and if I don't hit any graphql endpoint for a while, say 20 minutes, I have to restart the server all over again
The issue is on the /graphql endpoint which I am hitting like this
const app = new Elysia() .use(cors()) .use( apollo({ schema, path: "/graphql", enablePlayground: true, context: async ({ request }) => { return { db: queryClient }; }, } as ElysiaApolloConfig) ) .listen(8080);
Trying to disable the disbale the Apollo playground.
Setting
enablePlayground: false
weirdly disables the playground but enables the Apollo Sandbox.
Looking into how to disable sandbox i found that Apollo just accepts plugins to disable or change the behavior of the Sandbox.
When I try
new Elysia()
.use(
apollo({
path: "/test",
enablePlayground: false,
typeDefs,
resolvers,
plugins: [
// Install a landing page plugin based on NODE_ENV
process.env.NODE_ENV === "production"
? ApolloServerPluginLandingPageProductionDefault({
graphRef: "my-graph-id@my-graph-variant",
footer: false,
})
: ApolloServerPluginLandingPageLocalDefault({ footer: false }),
],
})
)
.listen(3000)
I get error
Type 'import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").ApolloServerPlugin<import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/context").BaseContext>' is not assignable to type 'import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").ApolloServerPlugin<import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/context").BaseContext>'.
Types of property 'serverWillStart' are incompatible.
Type '((service: import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerContext) => Promise<void | import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener>) | undefined' is not assignable to type '((service: import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerContext) => Promise<...>) | undefined'.
Type '(service: import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerContext) => Promise<void | import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener>' is not assignable to type '(service: import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerContext) => Promise<...>'.
Type 'Promise<void | import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener>' is not assignable to type 'Promise<void | import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener>'.
Type 'void | import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener' is not assignable to type 'void | import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener'.
Type 'GraphQLServerListener' is not assignable to type 'void | GraphQLServerListener'.
Type 'import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener' is not assignable to type 'import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").GraphQLServerListener'.
Types of property 'renderLandingPage' are incompatible.
Type '(() => Promise<import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage>) | undefined' is not assignable to type '(() => Promise<import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage>) | undefined'.
Type '() => Promise<import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage>' is not assignable to type '() => Promise<import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage>'.
Type 'Promise<import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage>' is not assignable to type 'Promise<import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage>'.
Type 'import("/home/user/Desktop/BunElysiaApollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage' is not assignable to type 'import("/home/user/Desktop/BunElysiaApollo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/externalTypes/plugins").LandingPage'.
Types of property 'html' are incompatible.
Type 'string | (() => Promise<string>)' is not assignable to type 'string'.
Type '() => Promise<string>' is not assignable to type 'string'.
When I set the context
in the Apollo Server Plugin, it doesn't get the request
object. I believe this is because of the way Apollo Server 4 changed their context object.
My code:
// Apollo Server Plugin for Elysia
app.use(
apollo({
path: '/graphql',
enablePlayground: true, // Default is disabled in production
typeDefs, // Import schema from .graphql file
resolvers, // Import resolvers from resolvers.js,
context: async (foo) => {
console.log('foo', foo); // {}
return {
dataSources: {
}
}
}
}),
);
In this case, any request I make the foo
object is empty {}
with no request information.
https://www.apollographql.com/docs/apollo-server/migration/#context-initialization-function
Could this be done in a similar way to how the express middleware for Apollo Server 4 handles the change?
Or maybe I'm missing something obvious to capture the request object in my context, if so, sorry!
How would we implement a drain plugin before shutdown? Of course, there is this plugin for apollo and express: https://www.apollographql.com/docs/apollo-server/api/plugin/drain-http-server/
But how would we do it in elysiajs?
I can write a simple drain plugin for apollo, but the problem seems that this elysia plugin never calls the stop() function of the apollo server on the stop signal from elysia.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.