schema.js
const { buildSchema } = require('graphql');
module.exports = buildSchema(`
type Booking {
_id: ID!
event: Event!
user: User!
}
type Event {
_id: ID!
title: String!
description: String!
price: Float!
creator: User
}
type User {
_id: ID!
email: String!
password: String
createdEvents: [Event!]
}
type RootQuery {
events: [Event!]!
users: [User!]!
bookings: [Booking!]!
}
schema {
query: RootQuery
}
`);
index.js
app.use(
'/graphql',
graphqlHTTP({
schema: graphQlSchema,
rootValue: graphQlResolvers,
graphiql: true
})
);
I am just trying to learn graphql and it's my first time so I am a little bit confused above query is working fine but what I want 3 different files for booking, user, event and merge them in a single file name index.js and after that import in the main index.js which is above one. This is the first time I am learning graphql. Any help will be appreciated
You could use Type definitions (SDL) merging of
graphql-tools
package to merge your type definition files.E.g.
types/booking.js
:types/user.js
:types/event.js
:types/index.js
:server.js
:Server logs: