Refactor GraphQL queries

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-06-10 10:06:23 +02:00
parent 1a0a31255f
commit c9e50da24a
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 286 additions and 393 deletions

View file

@ -1,35 +1,40 @@
import gql from "graphql-tag"; import gql from "graphql-tag";
const $addressFragment = ` export const ADDRESS_FRAGMENT = gql`
id, fragment AdressFragment on Address {
description, id
geom, description
street, geom
locality, street
postalCode, locality
region, postalCode
country, region
type, country
url, type
url
originId originId
}
`; `;
export const ADDRESS = gql` export const ADDRESS = gql`
query ($query: String!, $locale: String, $type: AddressSearchType) { query ($query: String!, $locale: String, $type: AddressSearchType) {
searchAddress( searchAddress(query: $query, locale: $locale, type: $type) {
query: $query, ...AdressFragment
locale: $locale,
type: $type
) {
${$addressFragment}
} }
} }
${ADDRESS_FRAGMENT}
`; `;
export const REVERSE_GEOCODE = gql` export const REVERSE_GEOCODE = gql`
query ($latitude: Float!, $longitude: Float!, $zoom: Int, $locale: String) { query ($latitude: Float!, $longitude: Float!, $zoom: Int, $locale: String) {
reverseGeocode(latitude: $latitude, longitude: $longitude, zoom: $zoom, locale: $locale) { reverseGeocode(
${$addressFragment} latitude: $latitude
longitude: $longitude
zoom: $zoom
locale: $locale
) {
...AdressFragment
} }
} }
${ADDRESS_FRAGMENT}
`; `;

View file

@ -1,179 +1,189 @@
import gql from "graphql-tag"; import gql from "graphql-tag";
import { ADDRESS_FRAGMENT } from "./address";
import { TAG_FRAGMENT } from "./tags";
const participantQuery = ` const PARTICIPANT_QUERY_FRAGMENT = gql`
role, fragment ParticipantQuery on Participant {
id, role
id
actor { actor {
preferredUsername, preferredUsername
avatar { avatar {
id id
url url
}, }
name, name
id, id
domain domain
}, }
event { event {
id, id
uuid uuid
}, }
metadata { metadata {
cancellationToken, cancellationToken
message message
}, }
insertedAt insertedAt
`;
const participantsQuery = `
total,
elements {
${participantQuery}
} }
`; `;
const physicalAddressQuery = ` const PARTICIPANTS_QUERY_FRAGMENT = gql`
description, fragment ParticipantsQuery on PaginatedParticipantList {
street, total
locality, elements {
postalCode, ...ParticipantQuery
region, }
country, }
geom, ${PARTICIPANT_QUERY_FRAGMENT}
type,
id,
originId
`; `;
const tagsQuery = ` const EVENT_OPTIONS_FRAGMENT = gql`
id, fragment EventOptions on EventOptions {
slug, maximumAttendeeCapacity
title remainingAttendeeCapacity
`; showRemainingAttendeeCapacity
anonymousParticipation
const optionsQuery = ` showStartTime
maximumAttendeeCapacity, showEndTime
remainingAttendeeCapacity,
showRemainingAttendeeCapacity,
anonymousParticipation,
showStartTime,
showEndTime,
offers { offers {
price, price
priceCurrency, priceCurrency
url url
}, }
participationConditions { participationConditions {
title, title
content, content
url url
}, }
attendees, attendees
program, program
commentModeration, commentModeration
showParticipationPrice, showParticipationPrice
hideOrganizerWhenGroupEvent, hideOrganizerWhenGroupEvent
__typename }
`;
const FULL_EVENT_FRAGMENT = gql`
fragment FullEvent on Event {
id
uuid
url
local
title
description
beginsOn
endsOn
status
visibility
joinOptions
draft
picture {
id
url
name
metadata {
width
height
blurhash
}
}
publishAt
onlineAddress
phoneAddress
physicalAddress {
...AdressFragment
}
organizerActor {
avatar {
id
url
}
preferredUsername
domain
name
url
id
summary
}
contacts {
avatar {
id
url
}
preferredUsername
name
summary
domain
url
id
}
attributedTo {
avatar {
id
url
}
preferredUsername
name
summary
domain
url
id
}
participantStats {
going
notApproved
participant
}
tags {
...TagFragment
}
relatedEvents {
id
uuid
title
beginsOn
picture {
id
url
name
metadata {
width
height
blurhash
}
}
physicalAddress {
id
description
}
organizerActor {
id
avatar {
id
url
}
preferredUsername
domain
name
}
}
options {
...EventOptions
}
}
${ADDRESS_FRAGMENT}
${TAG_FRAGMENT}
${EVENT_OPTIONS_FRAGMENT}
`; `;
export const FETCH_EVENT = gql` export const FETCH_EVENT = gql`
query FetchEvent($uuid: UUID!) { query FetchEvent($uuid: UUID!) {
event(uuid: $uuid) { event(uuid: $uuid) {
id, ...FullEvent
uuid,
url,
local,
title,
description,
beginsOn,
endsOn,
status,
visibility,
joinOptions,
draft,
picture {
id
url
name
},
publishAt,
onlineAddress,
phoneAddress,
physicalAddress {
${physicalAddressQuery}
}
organizerActor {
avatar {
id
url
},
preferredUsername,
domain,
name,
url,
id,
summary
},
contacts {
avatar {
id
url,
}
preferredUsername,
name,
summary,
domain,
url,
id
},
attributedTo {
avatar {
id
url,
}
preferredUsername,
name,
summary,
domain,
url,
id
},
participantStats {
going,
notApproved,
participant
},
tags {
${tagsQuery}
},
relatedEvents {
id
uuid,
title,
beginsOn,
picture {
id,
url
}
physicalAddress {
id
description
},
organizerActor {
id
avatar {
id
url,
},
preferredUsername,
domain,
name,
}
},
options {
${optionsQuery}
}
} }
} }
${FULL_EVENT_FRAGMENT}
`; `;
export const FETCH_EVENT_BASIC = gql` export const FETCH_EVENT_BASIC = gql`
@ -240,252 +250,129 @@ export const FETCH_EVENTS = gql`
# }, # },
category category
tags { tags {
slug ...TagFragment
title
} }
} }
} }
} }
${TAG_FRAGMENT}
`; `;
export const CREATE_EVENT = gql` export const CREATE_EVENT = gql`
mutation createEvent( mutation createEvent(
$organizerActorId: ID!, $organizerActorId: ID!
$attributedToId: ID, $attributedToId: ID
$title: String!, $title: String!
$description: String!, $description: String!
$beginsOn: DateTime!, $beginsOn: DateTime!
$endsOn: DateTime, $endsOn: DateTime
$status: EventStatus, $status: EventStatus
$visibility: EventVisibility, $visibility: EventVisibility
$joinOptions: EventJoinOptions, $joinOptions: EventJoinOptions
$draft: Boolean, $draft: Boolean
$tags: [String], $tags: [String]
$picture: MediaInput, $picture: MediaInput
$onlineAddress: String, $onlineAddress: String
$phoneAddress: String, $phoneAddress: String
$category: String, $category: String
$physicalAddress: AddressInput, $physicalAddress: AddressInput
$options: EventOptionsInput, $options: EventOptionsInput
$contacts: [Contact] $contacts: [Contact]
) { ) {
createEvent( createEvent(
organizerActorId: $organizerActorId, organizerActorId: $organizerActorId
attributedToId: $attributedToId, attributedToId: $attributedToId
title: $title, title: $title
description: $description, description: $description
beginsOn: $beginsOn, beginsOn: $beginsOn
endsOn: $endsOn, endsOn: $endsOn
status: $status, status: $status
visibility: $visibility, visibility: $visibility
joinOptions: $joinOptions, joinOptions: $joinOptions
draft: $draft, draft: $draft
tags: $tags, tags: $tags
picture: $picture, picture: $picture
onlineAddress: $onlineAddress, onlineAddress: $onlineAddress
phoneAddress: $phoneAddress, phoneAddress: $phoneAddress
category: $category, category: $category
physicalAddress: $physicalAddress physicalAddress: $physicalAddress
options: $options, options: $options
contacts: $contacts contacts: $contacts
) { ) {
id, ...FullEvent
uuid,
title,
url,
local,
description,
beginsOn,
endsOn,
status,
visibility,
joinOptions,
draft,
picture {
id
url
},
publishAt,
category,
onlineAddress,
phoneAddress,
physicalAddress {
${physicalAddressQuery}
},
attributedTo {
id,
domain,
name,
url,
preferredUsername,
avatar {
id
url
}
},
organizerActor {
avatar {
id
url
},
preferredUsername,
domain,
name,
url,
id,
},
contacts {
avatar {
id
url
},
preferredUsername,
domain,
name,
url,
id,
},
participantStats {
going,
notApproved,
participant
},
tags {
${tagsQuery}
},
options {
${optionsQuery}
}
} }
} }
${FULL_EVENT_FRAGMENT}
`; `;
export const EDIT_EVENT = gql` export const EDIT_EVENT = gql`
mutation updateEvent( mutation updateEvent(
$id: ID!, $id: ID!
$title: String, $title: String
$description: String, $description: String
$beginsOn: DateTime, $beginsOn: DateTime
$endsOn: DateTime, $endsOn: DateTime
$status: EventStatus, $status: EventStatus
$visibility: EventVisibility, $visibility: EventVisibility
$joinOptions: EventJoinOptions, $joinOptions: EventJoinOptions
$draft: Boolean, $draft: Boolean
$tags: [String], $tags: [String]
$picture: MediaInput, $picture: MediaInput
$onlineAddress: String, $onlineAddress: String
$phoneAddress: String, $phoneAddress: String
$organizerActorId: ID, $organizerActorId: ID
$attributedToId: ID, $attributedToId: ID
$category: String, $category: String
$physicalAddress: AddressInput, $physicalAddress: AddressInput
$options: EventOptionsInput, $options: EventOptionsInput
$contacts: [Contact] $contacts: [Contact]
) { ) {
updateEvent( updateEvent(
eventId: $id, eventId: $id
title: $title, title: $title
description: $description, description: $description
beginsOn: $beginsOn, beginsOn: $beginsOn
endsOn: $endsOn, endsOn: $endsOn
status: $status, status: $status
visibility: $visibility, visibility: $visibility
joinOptions: $joinOptions, joinOptions: $joinOptions
draft: $draft, draft: $draft
tags: $tags, tags: $tags
picture: $picture, picture: $picture
onlineAddress: $onlineAddress, onlineAddress: $onlineAddress
phoneAddress: $phoneAddress, phoneAddress: $phoneAddress
organizerActorId: $organizerActorId, organizerActorId: $organizerActorId
attributedToId: $attributedToId, attributedToId: $attributedToId
category: $category, category: $category
physicalAddress: $physicalAddress physicalAddress: $physicalAddress
options: $options, options: $options
contacts: $contacts contacts: $contacts
) { ) {
id, ...FullEvent
uuid,
title,
url,
local,
description,
beginsOn,
endsOn,
status,
visibility,
joinOptions,
draft,
picture {
id
url
},
publishAt,
category,
onlineAddress,
phoneAddress,
physicalAddress {
${physicalAddressQuery}
},
attributedTo {
id,
domain,
name,
url,
preferredUsername,
avatar {
id
url
}
},
contacts {
avatar {
id
url
},
preferredUsername,
domain,
name,
url,
id,
},
organizerActor {
avatar {
id
url
},
preferredUsername,
domain,
name,
url,
id,
},
participantStats {
going,
notApproved,
participant
},
tags {
${tagsQuery}
},
options {
${optionsQuery}
}
} }
} }
${FULL_EVENT_FRAGMENT}
`; `;
export const JOIN_EVENT = gql` export const JOIN_EVENT = gql`
mutation JoinEvent($eventId: ID!, $actorId: ID!, $email: String, $message: String, $locale: String) { mutation JoinEvent(
$eventId: ID!
$actorId: ID!
$email: String
$message: String
$locale: String
) {
joinEvent( joinEvent(
eventId: $eventId, eventId: $eventId
actorId: $actorId, actorId: $actorId
email: $email, email: $email
message: $message, message: $message
locale: $locale locale: $locale
) { ) {
${participantQuery} ...ParticipantsQuery
} }
} }
${PARTICIPANTS_QUERY_FRAGMENT}
`; `;
export const LEAVE_EVENT = gql` export const LEAVE_EVENT = gql`
@ -534,20 +421,21 @@ export const DELETE_EVENT = gql`
export const PARTICIPANTS = gql` export const PARTICIPANTS = gql`
query Participants($uuid: UUID!, $page: Int, $limit: Int, $roles: String) { query Participants($uuid: UUID!, $page: Int, $limit: Int, $roles: String) {
event(uuid: $uuid) { event(uuid: $uuid) {
id, id
uuid, uuid
title, title
participants(page: $page, limit: $limit, roles: $roles) { participants(page: $page, limit: $limit, roles: $roles) {
${participantsQuery} ...ParticipantsQuery
}, }
participantStats { participantStats {
going, going
notApproved, notApproved
rejected, rejected
participant participant
} }
} }
} }
${PARTICIPANTS_QUERY_FRAGMENT}
`; `;
export const EVENT_PERSON_PARTICIPATION = gql` export const EVENT_PERSON_PARTICIPATION = gql`