diff options
-rw-r--r-- | assets/punktacja.gql | 13 | ||||
-rw-r--r-- | pages/punktacja.vue | 25 |
2 files changed, 32 insertions, 6 deletions
diff --git a/assets/punktacja.gql b/assets/punktacja.gql new file mode 100644 index 0000000..3a6a9fa --- /dev/null +++ b/assets/punktacja.gql @@ -0,0 +1,13 @@ +type Troop { + name: String +} + +type Points { + troop: Troop + points: Int +} + +type Query { + getPoints: [Points!] + getTroopByName(name: String!): [Troop!] +} diff --git a/pages/punktacja.vue b/pages/punktacja.vue index 5f810ed..c263e5e 100644 --- a/pages/punktacja.vue +++ b/pages/punktacja.vue @@ -11,7 +11,18 @@ import RankingList from '~/components/Ranking/RankingList' const FAUNA_KEY = 'fnADeP_U0uACC4Hruw9JvjexNsvB-V-QjI3wr8yH' const b64encodedSecret = Buffer.from(FAUNA_KEY + ':').toString('base64') -const FAUNA_REF = '250230903625744898' +const query = ` +{ + getPoints{data {points troop{name}}} +}` +const URL = 'https://graphql.fauna.com/graphql' +const FETCH_OPTIONS = { + method: 'POST', + headers: { + Authorization: `Basic ${b64encodedSecret}` + }, + body: JSON.stringify({ query }) +} export default { components: { @@ -26,11 +37,13 @@ export default { this.getScores() }, methods: { - getScores() { - this.scores = [ - { troop: 'Toop 1', points: 1 }, - { troop: 'Troop 2', points: 2 } - ] + async getScores() { + const r = await fetch(URL, FETCH_OPTIONS) + const { data } = await r.json() + this.scores = data.getPoints.data.map(({ points, troop }) => ({ + troop: troop.name, + points + })) } } } |