Apollo Server
Install the adapter and peer deps
npm i @aexol/axolotl-core @aexol/axolotl-apollo-server @apollo/server graphql
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
is generated at the path you provide.
First, generate models with axolotl build
:
npx @aexol/axolotl build
Then write your files. The apolloServerAdapter()
returns an ApolloServer
instance; the simplest way to run it is via Apollo’s standalone server.
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}`);