Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

javascript - Graphql array of objects in parameter

I need to send graphql an array of objects in the parameter but I am getting an internal error "Cannot convert object to primitive value". Im not sure if this is on my backend or in the query itself. I cant find an example online where there is an array of objects in the parameter. Here is the query:

{
  searchProfile(query:"", limit: 10, sortBy: [{name: "name", sortOrder: "asc"}]){
    items{
      id
      name
      email
    }
    context
  }
} 

Im created a graphql wrapper for a rest api let me know if more information is needed like dataSource, or resolvers. Schema:

searchProfile(
  query: String
  sortBy: [JSONObject]
  cursor: String
  limit: Int
  context: JSONObject
): CustomerPagination

DataSource:

async searchProfile(query, sortBy, cursor, limit, context) {
    return this.get('getProfile/search', {
      ...(query && { query }),
      ...(sortBy && { sortBy }),
     ...other data ommitted
    });
  }

Resolvers.js:

searchCustomer: async (_, { query, sortBy, cursor, limit, context }, { dataSources }) => {
      return dataSources.api.searchProfile(query, sortBy, cursor, limit, context);
    },

Everything works until I added the sortBy param in the gql query.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...