Skip to content

Instantly share code, notes, and snippets.

@misterhtmlcss
Last active Feb 5, 2021
Embed
What would you like to do?

RW: v0.24

I have added a terminal print out at the bottom. It is quite large, so anyone who wants to see it all will need to click on the raw button next to that file to open it in a separate window to make it easier to read.

The upside is it's all there. The downside is that it is all there :)

# Am I supposed to rename this from .defaults to just .env?
FAUNA_SECRET_KEY="......"
import {
createGraphQLHandler,
makeMergedSchema,
makeServices,
} from '@redwoodjs/api'
import schemas from 'src/graphql/**/*.{js,ts}'
import services from 'src/services/**/*.{js,ts}'
import { db } from 'src/lib/db'
export const handler = createGraphQLHandler({
schema: makeMergedSchema({
schemas,
services: makeServices({ services }),
}),
db
})
import gql from 'graphql-tag'
export const schema = gql`
enum Role {
ADMIN
REFEREE
OTHER
}
type Arena {
title: String!
url: String!
address: String!
city: String!
postcode: String!
author: Author!
}
type Author {
role: Role!
name: String!
city: String!
arenas: [Arena] @relation
}
type Query {
allArenas: [Arena!]!
allAuthors: [Author!]!
findArenas(title: String!): [Arena!]
}
`
enum Role {
ADMIN
REFEREE
OTHER
}
type Arena {
title: String!
url: String!
address: String!
city: String!
postcode: String!
author: Author!
}
type Author {
role: Role!
name: String!
city: String!
arenas: [Arena] @relation
}
type Query {
allArenas: [Arena!]!
allAuthors: [Author!]!
findArenas(title: String!): [Arena!]
}
require('dotenv').config()
import { GraphQLClient } from 'graphql-request'
export const request = async (query = {}) => {
const endpoint = 'https://graphql.fauna.com/graphql'
const graphQLClient = new GraphQLClient(endpoint, {
headers: {
authorization: 'Bearer ' + process.env.FAUNA_SECRET_KEY
},
})
try {
return await graphQLClient.request(query)
} catch (error) {
console.error(error)
return error
}
}
import { request } from 'src/lib/db'
import { gql } from 'graphql-request'
export const arenas = async () => {
const query = gql`
allArenas {
data {
_id
name
url
address
city
postcode
}
}
`
const data = await request(query, 'https://graphql.fauna.com/graphql')
console.log("data", data);
return data['arenas']
}
export const QUERY = gql`
query allArenas {
allArenas {
data {
_id
name
url
address
city
postcode
}
}
}
`
export const Loading = () => <div>Loading...</div>
export const Empty = () => <div>No Arenas Yet!</div>
export const Failure = ({ error }) => <div>Error: {error.message}</div>
export const Success = ({ allArenas }) => {
const { data } = allArenas
return JSON.stringify(data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment