You don’t need those imports. Imports are required for fragment resolving.
Can you try simply removing those import statements? Are you receiving any errors then?
You only need to load all graphql files, and make sure to register all the types. Your Comment.graphql can use “undefined” types in that scope. It will be fixed upon register.
Thanks for your reply.
Yes it still work fine, if I don’t use #import .....
But I would like to split file (type, schema, resolvers) like this:
Comments
// comment.graphql
#import User "../uers/user.graphql"
type Comment {
title: String!
isDone: Boolean!
createdAt: Date!
user: User
}
type OtherCommentType {
..............
}
----------
// schema.js
#import Comment "./comment.grapql"
type Query {
getComments: [Comment]
}
---------
// resolvers.js
.........
Users
// user.graphql
#import Comment "../comments/comment.grapql"
type User {
_id: ID!
firstName: String!
lastName: String!
age: Int
comments: [Comment]
}
type OtherUserType {
..............
}
----------
// schema.js
#import User "./user.grapql"
type Query {
getUsers: [User]
}
---------
// resolvers.js
.........
Startup api
import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'
// Get schemas
import { typeDefs as userType, resolvers as userResolver} from './users/schema.js'
import { typeDefs as commentType, resolvers as commentResolver} from './comments/schema.js'
// Create apollo server
const server = new ApolloServer({
typeDefs: mergeTypes([userType, commentType], { all: true }),
resolvers: mergeResolvers([userResolver, commentResolver]),
.............