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

Categories

0 votes
3.8k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...