//graphql query
{
company(id: "2"){
id
name
description
}
}
keeping query before the graphql query{ } is optional,can be used to name your queries.
query findCompany{
company(id: "2"){
id
name
description
}
}
we can query multiple queries in a single query,but we will get duplicate element issue in the final json result.
{
company(id: "1"){
id
name
description
}
company(id: "2"){
id
name
description
}
}
so label them as below.
{
apple: company(id: "1"){
id
name
description
}
google: company(id: "2"){
id
name
description
}
}
use of fragments to remove duplication of code:
{
apple: company(id: "1"){
...companyDetails
}
google: company(id: "2"){
...companyDetails
}
}
fragment companyDetails on Company{
id
name
description
}
No comments:
Post a Comment