Adding Graphql
To add graphql to a remult
application follow these steps:
- Install the
graphql
andexpress-graphql
packages:shnpm i graphql express-graphql
- In the
/src/server/index.ts
file add the following code:tsimport express from 'express'; import { buildSchema } from 'graphql'; import { graphqlHTTP } from 'express-graphql'; import { remultGraphql } from 'remult/graphql'; import { remultExpress } from 'remult/remult-express'; const app = express(); let api = remultExpress(); app.use(api); const { schema, rootValue } = remultGraphql(api); app.use('/api/graphql', graphqlHTTP({ schema: buildSchema(schema), rootValue, graphiql: true, })); app.listen(3002, () => console.log("Server started"));