Apollo Server

Apollo Server

Install adapter

npm i @aexol/axolotl-core @aexol/axolotl-apollo-server

Now you need a schema.graphql file or a URL with settings to download the schema from upstream. Out of it Axolotl can generate simple type definitions needed for the library out of your GraphQL Schema.

models.ts are located where you specify when initiating Axolotl

First execute axolotl build command

npx @aexol/axolotl build

Then write your index.ts file. The apolloServerAdapter() will return ApolloServer object, so to start a server in easiest way you may use standalone server from apollo.

axolotl.ts
import { Axolotl } from '@aexol/axolotl-core';
import { apolloServerAdapter } from '@aexol/axolotl-apollo-server';
import { Models } from '@/src/models.js';
 
export const { createResolvers, adapter } = Axolotl(apolloServerAdapter)<Models>();
 
resolvers.ts
import { createResolvers } from '@/src/axolotl.js';
 
export default createResolvers({
    // your type-safe resolvers here
});
index.ts
import { startStandaloneServer } from '@apollo/server/standalone';
import { adapter, applyMiddleware } from '@/src/axolotl.js';
import resolvers from '@/src/resolvers.js';
 
const {url } = await startStandaloneServer(adapter({resolvers}))
console.log(`Server ready at ${url}`);