Reference Field

Sample Reference Query

Query

{
products {
name
category {
name
}
}
}

Output

{
"data": {
"products": [
{
"name": "ACME Hammer",
"category": [
{
"name": "ACME Products"
},
{
"name": "Shop Tools"
}
]
},
{
"name": "ACME Shovel",
"category": [
{
"name": "ACME Products"
},
{
"name": "Garden Tools"
}
]
}
]
}
}

Sample Union Type Query

Query

{
bookings {
property {
... on Hotel {
pricePerNight
suite
}
... on House {
rentPerMonth
numberOfBeds
}
... on Flat {
pricePerMonth
numberOfBeds
allowsPets
}
}
}
}

Filtering by Reference

When filtering by reference, you pass a subfilter on the reference you are trying to query by. In the example provided, we are querying by a reference called Category. For the sub filters, see the other documentation for the individual types such as the field name of type Single Line String on Category.

The sub-filter is then passed to the direct reference filter for either strict matching, inclusive matching or exclusive matching.

It is not currently possible to filter on Union Types.

Reference filters support:

  • _every
  • _some
  • _none

category_every: CategoryWhereInput

{
products(
where: { category_every: { name_in: ["ACME Products", "Garden Tools"] } }
) {
name
category {
name
}
}
}

category_some: CategoryWhereInput

{
products(where: { category_some: { name: "ACME Products" } }) {
name
category {
name
}
}
}

category_none: CategoryWhereInput

{
products(
where: { category_none: { name_in: ["ACME Products", "Garden Tools"] } }
) {
name
category {
name
}
}
}

Mutating a Reference

Mutation

mutation {
createProduct(
data: {
name: "ACME Drill"
category: {
create: { name: "Power Tools" }
connect: [{ name: "Shop Tools" }, { name: "ACME Products" }]
}
}
) {
name
category {
name
}
}
}

Output

{
"data": {
"createProduct": {
"name": "ACME Drill",
"category": [
{
"name": "Power Tools"
},
{
"name": "Shop Tools"
},
{
"name": "ACME Products"
}
]
}
}
}

Mutating an Union Type

Mutation

mutation {
createShop(
data: {
title: "Little Paris"
offers: {
create: { Pastry: { name: "Éclair" } }
connect: { Drink: { name: "Americano" } }
}
}
) {
title
}
}

Output

{
"data": {
"createShop": {
"title": "Little Paris"
}
}
}

Were you expecting something more?

We are constantly contributing to our documentation, but if you spot something we're missing, let us know and we'll be sure to add it.

This site uses cookies to provide you with a better user experience. For more information, refer to our Privacy Policy