Skip to content
Graffle is a work in progress. Learn more.

Alias

This example shows how to write GraphQL aliases in the TypeScript interface.

ts

import { 
Graffle
} from './graffle/__.js'
const
pokemon
=
Graffle
.
create
()
const
day
= 1000 * 60 * 60 * 24
const
year
=
day
* 365.25
const
yearsAgo100
= new
Date
(
Date
.
now
() -
year
* 100).
toISOString
()
const
yearsAgo1
= new
Date
(
Date
.
now
() -
year
).
toISOString
()
const
pokemons
= await
pokemon
.
query
.
$batch
({
pokemons
: [
[`elderPokemons`, {
$
: {
filter
: {
birthday
: {
lte
:
yearsAgo100
} } },
name
: true,
}], [`babyPokemons`, {
$
: {
filter
: {
birthday
: {
gte
:
yearsAgo1
} } },
name
: true,
}], ], }) console.log(
pokemons
)

Outputs

json
{
  "elderPokemons": [
    {
      "name": "Pikachu"
    },
    {
      "name": "Squirtle"
    }
  ],
  "babyPokemons": [
    {
      "name": "Charizard"
    }
  ]
}

Released under the MIT License.