Kindly let me know how to use the graphQL-module with new version of @apollo/server
I have tried following piece of code but no success yet. As in new version I can’t pass the value from
application.createApolloExecutor() in apollo server.
import { ApolloServer } from ‘@apollo/server’;
import { startStandaloneServer } from ‘@apollo/server/standalone’;
import { createApplication } from ‘graphql-modules’;
import { bookModule } from ‘./modules/index.js’;
const application = createApplication({
modules:[bookModule]
});
// Following commented lines of code is not working
// const executor = application.createApolloExecutor();
// const typeDefs = application.typeDefs;
// const resolvers = application.resolvers;
// const server = new ApolloServer({
// typeDefs,
// resolvers,
// });
const schema = application.schema;
const modules = application.ɵconfig.modules;
const server = new ApolloServer({schema:schema});
const { url } = await startStandaloneServer(server,{
listen: { port: 4000 },
});
console.log(🚀 Server ready at: ${url}
);
For further details please refer Error context.ɵgetModuleContext is not a function · Discussion #2292 · Urigo/graphql-modules · GitHub
Apollo Server 4 no longer supports the executor
option which it looks like your approach depends on. There’s a section in the migration guide for this here. I think you’ll want to return { schema, executor }
from the load
function, not just the { executor }
.
I think that is the right direction but I couldn’t seem to get it working
I am attempting to use the v4 @apollo/server combined with @as-integrations/next for use with nextjs topped with graphql-modules. The Apollo server works as expected when NOT using graphql-modules, as soon as I try to integrate I hit walls in every direction.
The below code results in the error: “You must call start() before getSchemaDerivedData()”
import {ApolloServer} from '@apollo/server';
import {createApplication, createModule, gql} from "graphql-modules";
import {startServerAndCreateNextHandler} from '@as-integrations/next';
import cors from "lib/cors";
const helloModule = createModule({
id: 'hello-module',
dirname: __dirname,
typeDefs: [
gql`
type Query {
hello: String!
}
`
],
resolvers: {
Query: {
hello: (parent, args, ctx, info) => {
return 'Hello'
}
}
}
})
export const application = createApplication({
modules: [helloModule]
});
const executor = application.createApolloExecutor();
const schema = application.schema;
const server = new ApolloServer({
gateway: {
async load() {
return {
schema,
executor
};
},
onSchemaLoadOrUpdate() {
return () => {
};
},
async stop() {
},
},
introspection: true,
csrfPrevention: true
});
const handler = startServerAndCreateNextHandler(server);
export default cors(handler);
Check out this link - Apollo 4 support · Issue #2270 · Urigo/graphql-modules · GitHub
I think I was facing a similar problem, and it seemed to solve the issue.
Hope this helps