Giter VIP home page Giter VIP logo

get-graphql-schema's People

Contributors

davemcorwin avatar felixfbecker avatar maticzav avatar schickling avatar thisismissem avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

get-graphql-schema's Issues

Relay compiler throws syntax error: unexpected “$” when running in Github Action

Description

Relay compiler throws Syntax Error: Unexpected "$". when compiling in Github Actions. This issue only does not occur in a local environment or if I commit the schema.graphql to and use this instead of downloaded a fresh copy.

I have raised a stack overflow post about this without much success: Relay compiler throws syntax error: Unexpected “$” when running in Github Action

I am using the vanilla create-react-app set up with the import graphql from "babel-plugin-relay/macro" fix as suggested here.

Here is the section of my yml file where is breaks:

    name: Lint, test and build
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, 'ci-skip')"
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: "12.x"
      - name: Restore cached dependencies
        uses: actions/cache@v1
        with:
          path: node_modules
          key: node-modules-${{ hashFiles('yarn.lock') }}
      - name: Install dependencies
        run: yarn install --frozen-lockfile
      - name: Run ESlint
        run: yarn run lint
      - name: Test using Jest
        run: yarn run test-ci 
        env:
          CI: true
      - name: Download GraphQL Schema
        run: SECRET=$SECRET ENDPOINT=$ENDPOINT yarn run get-schema
        env:
          SECRET: ${{ secrets.hasura_admin_secret }}
          ENDPOINT: ${{ secrets.graphql_endpoint }}
      - name: Test Compile Relay
        run: yarn run relay <<<<< this breaks
      - name: Test build
        run: yarn run build

And here are those scripts in my package.json.

"compile-css": "postcss src/index.css -o src/styles.css",
"build-compile-css": "NODE_ENV=production postcss src/index.css -o src/styles.css",
"start": "yarn run compile-css && react-scripts start",
"build": "yarn run build-compile-css && react-scripts build",
"get-schema": "yarn run get-graphql-schema -h \"x-hasura-admin-secret=$SECRET\" $ENDPOINT > schema.graphql",
"relay": "yarn run relay-compiler --schema ./schema.graphql --src ./src",
"test": "react-scripts test",
"test-ci": "react-scripts test --coverage --reporters=jest-junit",

It fails with the error:

$ /home/runner/work/<company-name>/<app-name>/node_modules/.bin/relay-compiler --schema schema.graphql --src src
Writing js
ERROR:
Syntax Error: Unexpected "$".

I have verified that schema is downloaded and the paths to the schema and src folder are correct.

Environment

    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-relay": "^10.0.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.1",
    "relay-runtime": "^10.0.1",

Is there a way I can debug this?

Error with JSON

error like this

{ FetchError: invalid json response body at http://localhost:18000/graphiql reason: Unexpected end of JSON input
    at /Users/johniexu/.nvm/versions/node/v10.13.0/lib/node_modules/get-graphql-schema/node_modules/node-fetch/lib/index.js:241:32
    at process._tickCallback (internal/process/next_tick.js:68:7)
  message:
   'invalid json response body at http://localhost:18000/graphiql reason: Unexpected end of JSON input',
  type: 'invalid-json' }

graphiql server created by postgraphifle, when i run get-graphql-schema http://localhost:18000/graphiql > schema.graphql, I got error

Include depreciated input values in introspection query

Currently, the default introspection query ignores any deprecated arguments for query and mutation inputs. Because they are excluded in the introspection query, the server won't even return them as potential values when saving the schema. When a value is deprecated, it should be available along with the deprecation reason since that will typically have instructions about other arguments to use instead so you can slowly migrate your code over to the new values.

Does not support invalid SSL certificates

Needs to have an option to enable this for local dev purposes

  process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
{ FetchError: request to https://localhost:3045/dev/graphql failed, reason: unable to verify the first certificate
    at ClientRequest.<anonymous> (/Users/t.gravity/.nvm/versions/node/v8.9.1/lib/node_modules/get-graphql-schema/node_modules/node-fetch/index.js:133:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'FetchError',

Introspect the multiple gql api

Hi,

Is there any way to introspect the multiple gql api into one graphql_schema.json? or merge two graphql_schema.json into one after introspect separately?

unicode replacement character

I created a schema using your tool to feed into graphdoc. However, the schema created contained a "\uFFFD" as the first character - which created issues with graphdoc.

is this a problem with your package?

get-graphql-schema Relay Schema with commas for multiple inheritance separators rejected by FB Relay Compiler

I am using a generated schema from Graph.Cool that has the User type implementing two interfaces: Node and AnonymousUser. This looks like standard multiple inheritance. The Relay Compiler rejects this, however if I use an ampersand it works (implements Node & AnonymousUser vs. implements Node, AnonymousUser). A change in the SDL spec seems to have caused the get-graphql-schema to fall out of date.

Reproduction
I'm able to reproduce this consistently

Expected behavior?
Commas should be converted to ampersands when listing inheritance references. FB Relay Team feedback confirms:

This is due to a change in the SDL spec that was implemented in graphql-js v0.13. While graphql-js can technically accept an option to enable legacy parsing, it is not exposed in relay-compiler.
The simplest way to make this work would be to make get-graphql-schema work with graphql-js v0.13

facebook/relay#2364

Add support for sending via multipart/form-data

Hey,

The back-end of my server uses asp.net core and to get graphql to work with uploading files I have to send my queries through as formdata with the uploadable files, e.g:

const network = Network.create((operation, variables, cacheConfig, uploadables = {}) => {
  const formData = new FormData();

  formData.append('query', operation.text);
  formData.append('variables', JSON.stringify(variables));

  Object.keys(uploadables).forEach((key) => {
    formData.append('uploadables', uploadables[key]);
  });

  return fetch('/graphql', {
    method: 'post',
    body: formData,
  }).then(response => response.json());
});

So, using this script doesn't work for me because asp.net core requires [FromBody] for json requests and we can't do both json and form-data in one graphql end-point.

So I created my own script that uses FormData to generate the schema. I could do a pull-request if you wanted with an option to use formdata instead of JSON.stringify and content-type: json.

Basic auth doesn't quite work

Hello, I've been trying to use the package with my own use case.

What's wrong

get-graphql-schema -j ${url} -h Authorization=base64EncodedCredsThatHas=Symbol

^ This doesn't quite work. I always get Error 401 Unauthorized

What I think happens

After checking the source code I found what I was expecting it to have:

const [key, value] = cli.flags.header.split('=')

So what I think that happens is that it also splits part of my encoded credentials and those parts are lost so it never sends the proper credentials to the server.

My suggestion

Change that line of code to something more safe, for example:

const breakPoint = header.find('='); // gets the first appearence of the '=' char
const key = header.substring(0, breakPoint);
const value = header.substring(breakPoint+1, header.length);
return {key, value};

Why didn't open a PR with my suggested patch?

I've tried to fork and clone the repo but I haven't been able to get it to fully npm install; running in a lot of dependency errors.

TypeError: Cannot read property '__schema' of undefined

When i try to get the graphql schema from my backend (graphcool), it doesn't work anymore. It worked the first time, but now it no longer works.

What could be the problem?

This is the issue thrown.

TypeError: Cannot read property '__schema' of undefined at Object.buildClientSchema (C:\Users\User\AppData\Roaming\npm\node_modules\get-graphql-schema\node_modules\graphql\utilities\buildClientSchema.js:48:43) at C:\Users\User\AppData\Roaming\npm\node_modules\get-graphql-schema\dist\index.js:89:54 at step (C:\Users\User\AppData\Roaming\npm\node_modules\get-graphql-schema\dist\index.js:33:23) at Object.next (C:\Users\User\AppData\Roaming\npm\node_modules\get-graphql-schema\dist\index.js:14:53) at fulfilled (C:\Users\User\AppData\Roaming\npm\node_modules\get-graphql-schema\dist\index.js:5:58) at <anonymous> at process._tickCallback (internal/process/next_tick.js:160:7)

Introduce option to selected types of interest

It would be nice to have a way to select which root type(s) from queryType/mutationType/subscriptionType should the command focus when given an option.

For example, something like:

get-graphql-schema -t query -t subscription ENDPOINT_URL > schema.graphql

Would only generate the schema with query and subscription types.

Add option to normalize the retrieved schema for usage in VCS

We use the tool to retrieve a schema and put in our VCS. The schema on the server isn't always in the same format/order, so a normalize option would be a nice features to avoid unneeded diffs.

@autotelic/graphql-schema-tools provices a simple module for this we use now as a separate tool.

schema.graphql generated as UTF-16 LE

When I use get-graphql-schema ENDPOINT_URL > schema.graphql my .graphql is generated as UTF-16 LE.

So when I try run yarn run relay at my react application I got the following error:

Error: Error loading schema. Expected the schema to be a .graphql or a .json
file, describing your GraphQL server's API. Error detail:

GraphQLError: Syntax Error: Cannot parse the unexpected character "\uFFFD".

To correct this problem I had to generate my .graphql on terminal, copy and paste in a new file that I created by myself on my app setting the name as schema.graphql.

With this approach, I was able set UTF-8 at my file and compile my queries using the relay command with yarn.

Is there another approach to fix this on windows?

FetchError: invalid json response body at http://localhost:4000/graphql reason: Unexpected token < in JSON at position 0

I'm trying a
$ get-graphql-schema http://localhost:4000/graphql > ./schema.graphql
And complain for this:

FetchError: invalid json response body at http://localhost:4000/graphql reason: Unexpected token < in JSON at position 0
    at /Users/romenigld/.asdf/installs/nodejs/12.13.1/.npm/lib/node_modules/get-graphql-schema/node_modules/node-fetch/lib/index.js:272:32
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  message: 'invalid json response body at http://localhost:4000/graphql reason: Unexpected token < in JSON at position 0',
  type: 'invalid-json'
}

Unknown option '--depthLimit'

When running the script i'm getting this error

npx gqlg --schemaFilePath apollo/directus/schema.graphql --destDirPath apollo/directus/queries-mutations_subscriptions --depthLimit 2
error: unknown option `--depthLimit'

when I last used the extension 2 months prior things worked without issues, not sure what happened.

generated .graphql output not compatible with relay

type Viewer {
  allFiles(filter: FileFilter, orderBy: FileOrderBy, skip: Int, after: String, before: String, first: Int, last: Int): FileConnection!
....

Relay Error :

Invariant Violation: RelaySchemaUtils: Expected type FileConnection!to be an object or interface type.

remove suffix ! on connection return type.

Does this tool support for Mac M1?

I'm try using:

npm install -g get-graphql-schema

and succefully. But I can't use this tool in my Mac M1.

 command not found: get-graphql-schema

Does this tool support for Mac M1?
Thanks.

move graphql to peerDependency

It would be great to move graphql into peerDependency ("graphql": "^14.0.2 || ^15") then we are not forced to pull 2 versions.

This is a simple change, but breaking change. is it feasible?

Error: []

I ran to a small issue when running this library. I am running the library directly from node_modules like so ./node_modules/.bin/get-graphql-schema [local_grapql_endpoint] > schema.graphql.

However I get:

Error: []
    at /node_modules/get-graphql-schema/dist/index.js:177:19
    at step (/node_modules/get-graphql-schema/dist/index.js:112:21)

The issue seems to be that the .json() function on the result returns an empty errors array. And it triggers https://github.com/prisma/get-graphql-schema/blob/2e8732322ba52158aa6bb163de3d7107a041cc52/src/index.ts#L65 to be true... If I remove the line from the source or check for errors.length > 0 it all works as expected.

Doing a little more research I found that this snippet also returns an empty array.

const fetch = require('node-fetch')

fetch(' [local_grapql_endpoint]')
  .then(res => res.json())
  .then(({errors}) => console.log(errors))

The solution to me seems to check if errors has length larger than 0, I could create a pull request if required.

License

Hi, really nice tool!

Could you provide it with a license? I know that the code is really basic, but I'd like to use your code and want to credit you guys and want to make sure that that's ok :)

Kind regards,

Michiel Westerbeek

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Syntax Error GraphQL request (1:2) Expected Name, found String \"query\"

I'm getting this error when running the following command:
get-graphql-schema -h Authorization=$AUTH_TOKEN https://my.graphql.endpoint.com > schema.graphql

Here is the full error output:

Error: [
  {
    "message": "Syntax Error GraphQL request (1:2) Expected Name, found String \"query\"\n\n1: {\"query\":\"\\n  query IntrospectionQuery {\\n    __schema {\\n      queryType { name }\\n      mutationType { name }\\n      subscriptionType { name }\\n      types {\\n        ...FullType\\n      }\\n      directives {\\n        name\\n        description\\n        locations\\n        args {\\n          ...InputValue\\n        }\\n      }\\n    }\\n  }\\n\\n  fragment FullType on __Type {\\n    kind\\n    name\\n    description\\n    fields(includeDeprecated: true) {\\n      name\\n      description\\n      args {\\n        ...InputValue\\n      }\\n      type {\\n        ...TypeRef\\n      }\\n      isDeprecated\\n      deprecationReason\\n    }\\n    inputFields {\\n      ...InputValue\\n    }\\n    interfaces {\\n      ...TypeRef\\n    }\\n    enumValues(includeDeprecated: true) {\\n      name\\n      description\\n      isDeprecated\\n      deprecationReason\\n    }\\n    possibleTypes {\\n      ...TypeRef\\n    }\\n  }\\n\\n  fragment InputValue on __InputValue {\\n    name\\n    description\\n    type { ...TypeRef }\\n    defaultValue\\n  }\\n\\n  fragment TypeRef on __Type {\\n    kind\\n    name\\n    ofType {\\n      kind\\n      name\\n      ofType {\\n        kind\\n        name\\n        ofType {\\n          kind\\n          name\\n          ofType {\\n            kind\\n            name\\n            ofType {\\n              kind\\n              name\\n              ofType {\\n                kind\\n                name\\n                ofType {\\n                  kind\\n                  name\\n                }\\n              }\\n            }\\n          }\\n        }\\n      }\\n    }\\n  }\\n\"}\n    ^\n",
    "locations": [
      {
        "line": 1,
        "column": 2
      }
    ]
  }
]
    
at /node_modules/get-graphql-schema/dist/index.js:83:31
at step (/node_modules/get-graphql-schema/dist/index.js:33:23)
at Object.next (/node_modules/get-graphql-schema/dist/index.js:14:53)
at fulfilled (/node_modules/get-graphql-schema/dist/index.js:5:58)
at process._tickCallback (internal/process/next_tick.js:109:7)

With Postman, requests with GraphQL syntax get a successful response, but when trying JSON syntax ({ "query": "...", "variables": null, "operationName": null }) it gives the same error as above.

Watch mode

This CLI should have a --watch mode to automatically update the schema file when the server schema changes.

Error while installing

/root
└── [email protected]

npm WARN enoent ENOENT: no such file or directory, open '/root/package.json'
npm WARN root No description
npm WARN root No repository field.
npm WARN root No README data
npm WARN root No license field.

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.