Search code examples
node.jsgraphqlapolloapollo-servergraphql-tools

Best way to model data in nested arrays across local and remote schemas in Apollo GraphQL?


I am new to graphql and apollo. I've got a local Graphql schema which is using nested arrays of objects and is mapped over to mongoDB in the resolvers with Mongoose.

type Category {
    id: ID!
    category: String!
    sections: [Section]
}

type SurveyType {
    id: ID!
    stype(type: SurveyTypeChoice): String
    categories: [Category] 
}

My queries to this work fine, but I also have a remote schema which is from a hasura instance I have running and maps on to a postgreSQL DB. This remote schema contains question information. I have merged these schemas using the graphql-tools module and can now query both schemas independently through my local apollo server instance.

My problem is that for the Section type in the schema above, i would like it to be in this format:

type Section {
    id: ID!
    section: String!
    leadText: String!
    questions: [Question] // Question here is an object from the remote schema
}

Is there a way to implement this kind of model and modify the resolvers such that I could query down to the Section level and obtain the array of questions from the remote schema?

Or am I barking up the wrong tree? If so can anyone think of a better way to model this kind of data across schemas?

Any suggestions would be much appreciated! thanks


Solution

  • I am also a newbie with GraphQL. I personally have not used Hasura, but I recently found this issue and I think it can help you solve your issue. It is really declarative and contains lots of details on how to implement a sample solution.

    I hope that helps! Please let me know if it helped you solve your problem.