grapher icon indicating copy to clipboard operation
grapher copied to clipboard

Graphql, astToQuery and subarrays

Open promentol opened this issue 5 years ago • 1 comments

Here is my typeDefs and resolvers

    type Query {
      professionals(companyId: String!): [Professional]
      company(route: String!): Company
    }

    type Company {
      name: String!
      route: String
      professionals: [Professional]
    }

    type Professional {
      name: String!
      avatar: String
      company: Company
      services: [Service]
    }

    type Service {
      _id: String
      name: String
      price: String
      duration: Int
      categoryId: String!
    }
company(_, args, { db }, ast) {
        
        return db.companies.astToQuery(ast, {
          $filters: {
            route: args.route
          }
        }).fetchOne()
      },
professionals(_, args, { db }, ast) {
        return db.professionals.astToQuery(ast, {
          $filters: {
            companyId: args.companyId
          }
        }).fetch();
      },

The problem is when querying companies, the services have the following result

{
   name: [..],
   price: [..]   
}

Here is my query. Queries professionals works normally

query {
  company(route: "_") {
    name,
    professionals {
      name,
      services {
      	_id,
        name,
        price
      }
    }
  }
}

promentol avatar Sep 14 '19 08:09 promentol

How did you link company and professionals inside grapher ?

theodorDiaconu avatar Sep 30 '19 07:09 theodorDiaconu