Skip to content

Instantly share code, notes, and snippets.

@yann-yinn
Last active September 3, 2020 13:06
Show Gist options
  • Save yann-yinn/50a40f222df67a86e7c5beaaf6b29a34 to your computer and use it in GitHub Desktop.
Save yann-yinn/50a40f222df67a86e7c5beaaf6b29a34 to your computer and use it in GitHub Desktop.
api.graphql
# Draft API technique :
# calqué sur mongoDB: il y a toujours une clef libre "filter" et "sort"
# Pour éviter de créer des méthodes de type postById, postBySlug, postBy{fieldName}
#
# récupérer une liste de post pour un blog particulier
#
{
posts(
first: 50
filter: { blog: {$eq: "5f4f7b367d6b1f0004b6c346"} }
sort: { publishedAt: desc }
) {
edges {
node {
_id
title
slug
blog
}
}
}
}
#
# récupérer un seul post par son slug
#
{
post(filter: { slug: {$eq: "premier-article"}, blog: {$eq: "5f4f7b367d6b1f0004b6c346"} } ) {
_id
title
slug
blog
}
}
#
# récupérer un seul post par son id
#
{
post(filter: { _id: $eq: {"5f4f7b3d7d6b1f0004b6c348"} }) {
title
slug
blog
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment