aaronwlee/oak-graphql

How To connect two Types(Resolve function in type defination)

Closed this issue · 3 comments

hey i've been using your middleware framework with oak , it's working great , but since it takes types/mutations/query as a string , i encountered one problem. my problem is that how to connect two types with each other?

back in node it was like

const BookType = new GraphQLObjectType({
  name: "Book",
  fields: () => ({
    id: { type: GraphQLID } //this is done,
    name: { type: GraphQLString } // this is done,
    genre: { type: GraphQLString } // this is done,
   //-----------------how to do this-----------------------
    author: {
      type: AuthorType,
      resolve: (parent, args) => {
        return AuthorModel.findById(parent.authorId);
      },
    },
  //-----------------how to do this-----------------------
  }),
});

const AuthorType = new GraphQLObjectType({
  name: "Author",
  fields: () => ({
    id: { type: GraphQLID } // this is done,,
    name: { type: GraphQLString }, // this is done
    age: { type: GraphQLInt }, // this is done
    //-----------------how to do this-----------------------
     books: {
      type: new GraphQLList(BookType),
      resolve: (parent, args) => {
        return BookModel.find({ authorId: parent.id });
      },
    },
  //-----------------how to do this-----------------------
  }),
});

in deno

const types = (gql as any)`
type author{
name:String!,
id:ID!,
genre:String!,
book // ---->  how to do this? how to write resolve function for this?
}
`

I want to know how to implement a block of code which says how to do this , i mean how to connect both types since it takes string i dont know how to implement it...

Thanks in Advance , I really appreciate your work...

This GraphQL concept is used in Apollo, it'll work exactly the same as it.
https://www.apollographql.com/docs/apollo-server/schema/schema/

i don't understand , where do i have to write resolve function of type which is inside another type
consider me as a noob, please help

Thanks

Got it, it's available in docs

Thanks for help