5.7 KiB
5.7 KiB
GraphQL Query Examples
The project exposes the GraphQL endpoint at /graphql, and in development GraphiQL is available at /.
Defined queries
The following queries are defined in Queries.cs:
countriessportspeoplepeoplePage(pageNumber, pageSize)eventseventsForDate(date)registrations
The countries, sports, people, events, eventsForDate, and registrations queries support:
- paging via
first,after,last,before - filtering via the
whereargument - sorting via the
orderargument totalCountbecause it is enabled in paging options
Basic examples
1. Get countries
query {
countries(first: 10) {
totalCount
nodes {
code
alpha3
name
}
}
}
2. Get sports
query {
sports(first: 10, order: [{ name: ASC }]) {
nodes {
id
name
}
}
}
3. Get people
query {
people(first: 10) {
totalCount
nodes {
id
firstName
lastName
email
city
birthDate
countryCode
}
}
}
4. Get events
query {
events(first: 10, order: [{ eventDate: DESC }]) {
nodes {
id
name
eventDate
}
}
}
5. Get registrations
query {
registrations(first: 10) {
nodes {
id
registeredAt
personId
sportId
eventId
}
}
}
Filtering and sorting examples
6. Countries whose name contains "Bos"
query {
countries(
first: 10
where: { name: { contains: "Bos" } }
order: [{ name: ASC }]
) {
nodes {
code
name
}
}
}
7. People from a specific country
query {
people(
first: 10
where: { countryCode: { eq: "HR" } }
order: [{ lastName: ASC }, { firstName: ASC }]
) {
totalCount
nodes {
id
firstName
lastName
city
countryCode
}
}
}
8. People born after a given date
query {
people(
first: 10
where: { birthDate: { gt: "2000-01-01" } }
order: [{ birthDate: DESC }]
) {
nodes {
id
firstName
lastName
birthDate
}
}
}
9. Events for an exact date
query {
eventsForDate(date: "2026-06-15", first: 20) {
totalCount
nodes {
id
name
eventDate
}
}
}
10. Events whose name contains a word
query {
events(
first: 10
where: { name: { contains: "Open" } }
order: [{ eventDate: ASC }]
) {
nodes {
id
name
eventDate
}
}
}
11. Registrations with nested data
query {
registrations(first: 10, order: [{ registeredAt: DESC }]) {
nodes {
id
registeredAt
person {
id
firstName
lastName
}
sport {
id
name
}
event {
id
name
eventDate
}
}
}
}
Paging examples
12. pageInfo for cursor paging
query {
people(first: 5, order: [{ id: ASC }]) {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
id
firstName
lastName
}
}
}
13. Next page using a cursor
query {
people(first: 5, after: "PUT_END_CURSOR_HERE") {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
firstName
lastName
}
}
}
14. Custom page query peoplePage
This query does not use cursor paging. It uses classic pageNumber and pageSize.
query {
peoplePage(pageNumber: 2, pageSize: 5) {
totalCount
pageNumber
pageSize
items {
id
firstName
lastName
email
}
}
}
Examples with variables
15. eventsForDate with variables
query EventsForDate($date: Date!) {
eventsForDate(date: $date, first: 20) {
nodes {
id
name
eventDate
}
}
}
Variables:
{
"date": "2026-06-15"
}
16. peoplePage with variables
query PeoplePage($pageNumber: Int!, $pageSize: Int!) {
peoplePage(pageNumber: $pageNumber, pageSize: $pageSize) {
totalCount
pageNumber
pageSize
items {
id
firstName
lastName
}
}
}
Variables:
{
"pageNumber": 1,
"pageSize": 10
}
Existing mutations
Even though this document focuses on queries, the project also defines these mutations for the Event entity:
addEvent(input)updateEvent(id, input)deleteEvent(id)
17. Add an event
mutation {
addEvent(input: { name: "Street Basketball 2026", eventDate: "2026-07-01" }) {
id
name
eventDate
}
}
18. Update an event
mutation {
updateEvent(
id: 1
input: { name: "Street Basketball 2026", eventDate: "2026-07-02" }
) {
id
name
eventDate
}
}
19. Delete an event
mutation {
deleteEvent(id: 1)
}
Fields by type
Useful fields visible from the models:
Country:code,alpha3,name,translationsSport:id,namePerson:id,firstName,lastName,firstNameTranscription,lastNameTranscription,addressLine,postalCode,city,addressCountry,email,contactPhone,birthDate,documentNumber,countryCodeEvent:id,name,eventDateRegistration:id,personId,sportId,eventId,registeredAt
Source
Examples are based on the implementation in:
Events.GraphQLServer/SetupGraphQL/Queries.csEvents.GraphQLServer/SetupGraphQL/Mutations.Event.csEvents.GraphQLServer/SetupGraphQL/PeoplePage.csEvents.GraphQLServer/SetupGraphQL/EventInput.csEvents.EF/Models/*.cs