admin管理员组文章数量:1126451
I have that query in GraphQL
query getUserByName($name: String!) {
user(name: $name) {
id
name
email
}
}
I want to get all users that contains Jon in name
, not equal.
How can I modify the query to do contains please (without edit the server side)
I have that query in GraphQL
query getUserByName($name: String!) {
user(name: $name) {
id
name
email
}
}
I want to get all users that contains Jon in name
, not equal.
How can I modify the query to do contains please (without edit the server side)
Share Improve this question edited Jan 8 at 22:12 Barmar 780k56 gold badges542 silver badges656 bronze badges asked Jan 8 at 21:32 Polo1990Polo1990 1237 bronze badges2 Answers
Reset to default 1That will depend on the schema / API provided by the server. If filters according to the partial match for the name
field are not supported there, you won't be able to do that solely via GraphQL.
Alternatively, what you can do is query all of the data and then perform the filtering on the client side. Just keep in mind that depending on the data volume, this approach might be problematic since it's not considered an efficient approach.
Unfortunately, the question you're asking is impossible to answer. It is possible that you misunderstand what GraphQL is, so I'll suggest: think of GraphQL like you would think of REST. This isn't the perfect analogy, but pretending it was, I'll rephrase your question using REST:
I have a REST API. I am making this curl request:
curl -X GET "https://api.example.com/users?name=Jon"
I want to get all users that contains Jon in name, not equal.
How can I modify the request to do contains please (without edit the server side)
Obviously the answer to this question would be
I have no idea. The only person who can answer this is the person who created your REST API. If, however, they're using some library or framework on top of the REST, that particular framework may have pre-defined rules on how to do what you're asking. Unfortunately, 'it is REST' means very little, because literally anything could be happening behind the scenes, as long as it has the properties of a REST API (client-server architecture, stateless operations, cacheability, a uniform interface, layered system, and optionally, code-on-demand).
GraphQL is a query language for an API (like REST), and an API can do ANYTHING. It is not a query language for data (like SQL).
As a deeper example, from what you've defined here, what follows are a valid GraphQL Schema and a valid JavaScript resolver of that data:
type Anxiety {
id: Float
name: Boolean
email: Int
}
type Query {
user(name: String): Anxiety
}
const resolvers = {
Query: {
user: () => {
return { id: Math.PI, name: false, email: 5987319 };
}
}
}
Note that from this code, it is impossible to do what you're asking for. I don't have any functionality that looks anything up in any database. I don't look at the arguments you passed in. I'm not even returning a "User"; it's an "Anxiety", and the field types aren't exactly what a person would expect them to be from their name.
Obviously this is an absurd example, but the fact that this is all "correct from the standpoint of GraphQL" proves my point I think. GraphQL can do literally anything behind the scenes, as long as the input is in the format defined in the schema and the response is in the format defined in the schema.
本文标签: databaseHow to use contain in GraphQL queryStack Overflow
版权声明:本文标题:database - How to use contain in GraphQL query - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736686823a1947711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论