GithubHelp home page GithubHelp logo

ptpaterson / faunadb-graphql-schema-loader Goto Github PK

View Code? Open in Web Editor NEW
14.0 14.0 1.0 1.13 MB

A package for making GraphQL schemas easy to work with using FaunaDB.

License: MIT License

JavaScript 6.66% TypeScript 93.34%
faunadb graphql typescript

faunadb-graphql-schema-loader's People

Contributors

dependabot[bot] avatar ptpaterson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

emenoh

faunadb-graphql-schema-loader's Issues

Rendering Response message on browser

Render helpful successful import message on client

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?

More context

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?

Module not found after installing with npm

I get the following error on importing this library after installing with npm.

Screen Shot 2020-09-11 at 12 02 22 PM

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.