diff --git a/client/src/Components/Event/Edit/index.js b/client/src/Components/Event/Edit/index.js index 0bc8a1cf6..d705b7e60 100644 --- a/client/src/Components/Event/Edit/index.js +++ b/client/src/Components/Event/Edit/index.js @@ -1,5 +1,4 @@ import React from 'react' -import gql from 'graphql-tag' import { Query } from 'react-apollo' import Typography from '@material-ui/core/Typography' @@ -7,22 +6,7 @@ import { withStyles } from '@material-ui/core/styles' import styles from './styles' -const HOSTS_EVENT = gql` - query Hosts_Event($designator: ID!){ - hosts_Event(designator: $designator) { - name - designator - startDatetime - finishDatetime - host { - alias - firstName - lastName - } - description - } - } -` +import { showEventCalls } from '../../GraphQL/Calls/index' class Edit extends React.Component { render () { @@ -37,7 +21,7 @@ class Edit extends React.Component { Enroll in an competition {this.props.match.params.slug} {({ loading, error, data }) => { diff --git a/client/src/Components/HostedEvents/graphql.js b/client/src/Components/GraphQL/Calls/hostedEvents.js similarity index 56% rename from client/src/Components/HostedEvents/graphql.js rename to client/src/Components/GraphQL/Calls/hostedEvents.js index ac617d6a3..850290690 100644 --- a/client/src/Components/HostedEvents/graphql.js +++ b/client/src/Components/GraphQL/Calls/hostedEvents.js @@ -1,29 +1,23 @@ import gql from 'graphql-tag' +import { eventMinimalInfo } from '../Fragments' -const fragments = ` - name - designator - startDatetime - finishDatetime - host { - alias - firstName - lastName - } - description -` - -export const HOSTS_HOSTEVENT = gql` +const HOSTS_HOSTEVENT = gql` mutation Hosts_HostEvent($name: String!, $description: String!, $startDatetime: Int!, $finishDatetime: Int!) { hosts_HostEvent(name: $name, description: $description, startDatetime: $startDatetime, finishDatetime: $finishDatetime) { - ${fragments} + ...EventMinimalInfo } } + ${eventMinimalInfo} ` -export const HOSTS_EVENTSBYHOST = gql` +const HOSTS_EVENTSBYHOST = gql` query Hosts_EventsByHost{ hosts_EventsByHost { - ${fragments} + ...EventMinimalInfo } } + ${eventMinimalInfo} ` +export default { + HOSTS_HOSTEVENT, + HOSTS_EVENTSBYHOST +} diff --git a/client/src/Components/GraphQL/Calls/index.js b/client/src/Components/GraphQL/Calls/index.js new file mode 100644 index 000000000..953d0edfb --- /dev/null +++ b/client/src/Components/GraphQL/Calls/index.js @@ -0,0 +1,7 @@ +import hostedEventsCalls from './hostedEvents' +import showEventCalls from './showEvent' + +export { + hostedEventsCalls, + showEventCalls +} diff --git a/client/src/Components/GraphQL/Calls/showEvent.js b/client/src/Components/GraphQL/Calls/showEvent.js new file mode 100644 index 000000000..1f06bf226 --- /dev/null +++ b/client/src/Components/GraphQL/Calls/showEvent.js @@ -0,0 +1,15 @@ +import gql from 'graphql-tag' +import { eventFullInfo } from '../Fragments' + +const HOSTS_EVENT = gql` + query Hosts_Event($designator: ID!) { + hosts_Event(designator: $designator) { + ...EventFullInfo + } + } + ${eventFullInfo} +` + +export default { + HOSTS_EVENT +} diff --git a/client/src/Components/GraphQL/Fragments/event.js b/client/src/Components/GraphQL/Fragments/event.js new file mode 100644 index 000000000..3b5f3c3ac --- /dev/null +++ b/client/src/Components/GraphQL/Fragments/event.js @@ -0,0 +1,61 @@ +import gql from 'graphql-tag' + +export const eventMinimalInfo = gql` + fragment EventMinimalInfo on hosts_Event { + name + designator + startDatetime + finishDatetime + host { + alias + firstName + lastName + } + description + } +` + +export const eventFullInfo = gql` + fragment EventFullInfo on hosts_Event { + designator + name + host{ + alias + firstName + lastName + } + description + startDatetime + finishDatetime + formula{ + name + } + plotter{ + name + host + repo + moduleName + } + rules{ + position + title + description + } + participants{ + team{ + name + } + botId + releaseId + } + prizes{ + rank + amount + additional{ + condition + amount + asset + } + } + } +` diff --git a/client/src/Components/GraphQL/Fragments/index.js b/client/src/Components/GraphQL/Fragments/index.js new file mode 100644 index 000000000..93d8f9971 --- /dev/null +++ b/client/src/Components/GraphQL/Fragments/index.js @@ -0,0 +1,9 @@ +import { + eventMinimalInfo, + eventFullInfo +} from './event' + +export { + eventMinimalInfo, + eventFullInfo +} diff --git a/client/src/Components/HostedEvents/New.js b/client/src/Components/HostedEvents/New.js index 9c8ceec45..1a574aa50 100644 --- a/client/src/Components/HostedEvents/New.js +++ b/client/src/Components/HostedEvents/New.js @@ -1,6 +1,6 @@ import React from 'react' import { Mutation } from 'react-apollo' -import { HOSTS_HOSTEVENT, HOSTS_EVENTSBYHOST } from './graphql' +import { hostedEventsCalls } from '../GraphQL/Calls/index' import { DateTime } from 'luxon' import { @@ -24,11 +24,11 @@ class New extends React.Component { render () { const { name, description, startDatetime, finishDatetime } = this.state return ( - { - const { hosts_EventsByHost: hostedEvents } = store.readQuery({ query: HOSTS_EVENTSBYHOST }) + const { hosts_EventsByHost: hostedEvents } = store.readQuery({ query: hostedEventsCalls.HOSTS_EVENTSBYHOST }) store.writeQuery({ - query: HOSTS_EVENTSBYHOST, + query: hostedEventsCalls.HOSTS_EVENTSBYHOST, data: { hosts_EventsByHost: hostedEvents.concat([data.hosts_HostEvent]) } }) this.props.handleNewEvent(data.hosts_HostEvent) diff --git a/client/src/Components/HostedEvents/index.js b/client/src/Components/HostedEvents/index.js index 08ef6829f..acb777684 100644 --- a/client/src/Components/HostedEvents/index.js +++ b/client/src/Components/HostedEvents/index.js @@ -1,6 +1,5 @@ import React from 'react' import { Query } from 'react-apollo' -import { HOSTS_EVENTSBYHOST } from './graphql' import { Button, @@ -13,6 +12,8 @@ import { import { withStyles } from '@material-ui/core/styles' import styles from './styles' +import { hostedEventsCalls } from '../GraphQL/Calls/index' + import New from './New' import Event from './Event' @@ -33,7 +34,7 @@ class HostedEvent extends React.Component { return ( {({ loading, error, data }) => { if (loading) return 'Loading...'