ptpaterson / faunadb-graphql-schema-loader Goto Github PK
View Code? Open in Web Editor NEWA package for making GraphQL schemas easy to work with using FaunaDB.
License: MIT License
A package for making GraphQL schemas easy to work with using FaunaDB.
License: MIT License
FYI looks like the 0.2.0 version on NPM was not built prior to publishing? It doesn't include the endpoint param in importSchema and always posts to https://graphql.fauna.com/import instead of the endpoint provided in the function call.
I can run my importSchema
API successfully server-side and receive this helpful message when I console.log()
the response:
Schema imported successfully.
Use the following HTTP header to connect to the FaunaDB GraphQL API:
{ "Authorization": "Bearer <SECRET_KEY" }
Perhaps this is forbidden due to potential security issues regarding the secret key, but I've been trying to render this message on the browser.
I can successfully receive the Response object from my API endpoint; however, when I console.log()
it, what is returned is not the helpful message, but instead, an entire Response object which is void of such a helpful message.
Is there some way to replicate this "Schema imported successfully." message on the client/browser?
Currently, I've been experimenting in trying to render this message on the browser using a hook like the following:
function useImportSchema() {
const [schema, setSchema] = useState([])
const [loading, setLoading] = useState(true)
useEffect(() => {
fetch('api/importSchema')
.then(data => data.body.getReader().read())
.then(text => {
setSchema(text)
setLoading(false)
})
}, [])
return [schema, loading]
}
I've tried .json()
, text()
, and .body
response objects, and none seem to be returning the desired message (excluding the full Response object returned when using body
.
Any possible workarounds to still provide a success message to the user on the browser?
I get the following error on importing this library after installing with npm
.
This is what my code looks like:
import { importSchema } from 'faunadb-graphql-schema-loader'
const secretKey = process.env.FAUNADB_ADMIN_KEY
const schema = `
type Crypto {
id: Int!
name: String!
symbol: String!
slug: String!
num_market_pairs: Int
date_added: String
tags: [String]
circulating_supply: Float
total_supply: Float
cmc_rank: Int
last_updated: String
}
type Query {
cryptos: [Crypto!]
crypto(name: String): Crypto
}
`
importSchema(secretKey, schema).then(res => console.log(res))
I also tried using require
to import, but that resulted in the same error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.