0

I am having problems trying to resolve fields inside a GraphQL type. So, here I am trying to resolve the find property of patientQuery

const gqlSchema = makeExecutableSchema({
    typeDefs: `
  type patientQuery {
    find: [String]
    findOne: String
  }
  type Query {
    patient: patientQuery
  }
  type Mutation {
    addPost(name: String, title: String, content: String): patientQuery
  }
  schema {
    query: Query
    mutation: Mutation
  }
  `,
    resolvers: {
      patientQuery: {
        find(root, params, context, ast) {
          console.log('testing');
          return ['title'];
        }
      }
    }
  });

but when I do a query like this

{
  patient {
    find
  }
}

I always get null

{
  "data": {
    "patient": null
  }
}

So what is the proper way to resolve the fields inside the patientQuery type?

Shalkam
  • 733
  • 6
  • 12
  • At first look, I suspect it has to do with the fact that you're returning a string but the field is expected to return an array of string. Try returning `return ['title']` – XuoriG Feb 27 '17 at 22:12
  • changed the resolve function returning an array but still I get null – Shalkam Feb 28 '17 at 07:24

1 Answers1

1

So, I've found out the problem. The Query type had to resolve the patient field so that it won't return null.

So the new resolvers object will look like this, in order to solve the issue

 resolvers: {
  Query: {
    patient() {
      return true;
    }
  },
  patientQuery: {
    find(root, params, context, ast) {
      console.log('testing');
      return [ 'title' ];
    }
  }
}

the old one :-

resolvers: {
  patientQuery: {
    find(root, params, context, ast) {
      console.log('testing');
      return ['title'];
    }
  }
}
Shalkam
  • 733
  • 6
  • 12