Giter VIP home page Giter VIP logo

Comments (15)

codeguy avatar codeguy commented on May 14, 2024 2

That's fair. You should drop a note in the readme that says the project doesn't work until this issue is fixed.

from graphql-schema-from-json.

konsumer avatar konsumer commented on May 14, 2024 2

I made this, which is not as complete, but it fit my purpose and doesn't throw errors. It also works for protobuf & jsonschema.

from graphql-schema-from-json.

codeguy avatar codeguy commented on May 14, 2024 1

I am also running into this issue. Do you have an ETA on a fix?

from graphql-schema-from-json.

flomair avatar flomair commented on May 14, 2024 1

While this is brocken i recomend this workarround:
create GraphQL server from data with json-graphql-server.
Extract GraphQL schema with get-graphql-schema

from graphql-schema-from-json.

fzaninotto avatar fzaninotto commented on May 14, 2024

ping @djhi

from graphql-schema-from-json.

djhi avatar djhi commented on May 14, 2024

Yes, that's due to conflicting references to the graphql package. Haven't found time to investigate and fix this yet

from graphql-schema-from-json.

lucianlature avatar lucianlature commented on May 14, 2024

Different graphql packages are being used across, so a quick fix for it is to import printSchema, then make that function available in the lib, and use that specific function.

from graphql-schema-from-json.

WhynoChinese avatar WhynoChinese commented on May 14, 2024

How can I get the generated schemaString ?
It does not look like this format
image

from graphql-schema-from-json.

acusti avatar acusti commented on May 14, 2024

@djhi I ran into a similar error as the original poster even when I created a brand new project with no other dependencies. I made a repo you can use to try it out: https://github.com/acusti/graphql-schema-from-json-test/. From that repo, I’ve listed the relevant files below.

Here’s package.json:

{
  "name": "a",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "graphql-schema-from-json": "^0.0.3"
  }
}

Here’s index.js (based on the README example):

const getSchemaFromData = require('graphql-schema-from-json').default;
const { printSchema } = require('graphql');

const data = {
    posts: [
        { id: 1, title: "Lorem Ipsum", views: 254, user_id: 123 },
        { id: 2, title: "Sic Dolor amet", views: 65, user_id: 456 },
    ],
    users: [
        { id: 123, name: "John Doe" },
        { id: 456, name: "Jane Doe" }
    ],
    comments: [
        { id: 987, post_id: 1, body: "Consectetur adipiscing elit", date: new Date('2017-07-03') },
        { id: 995, post_id: 1, body: "Nam molestie pellentesque dui", date: new Date('2017-08-17') }
    ]
}

// Get the schema as a JSON object
const schema = getSchemaFromData(data);

// Print the GQL for this schema
console.log(printSchema(schema));

When I run yarn start (or npm start), I get:

/Users/andrew/Projects/a/node_modules/graphql/jsutils/invariant.js:18
    throw new Error(message);
    ^

Error
    at invariant (/a/node_modules/graphql/jsutils/invariant.js:18:11)
    at printType (/a/node_modules/graphql/utilities/schemaPrinter.js:151:83)
    at Array.map (<anonymous>)
    at printFilteredSchema (/a/node_modules/graphql/utilities/schemaPrinter.js:80:87)
    at printSchema (/a/node_modules/graphql/utilities/schemaPrinter.js:44:10)
    at Object.<anonymous> (/a/index.js:23:13)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
error Command failed with exit code 1.

When I then run yarn list, the results show no duplicate graphql dependency:

yarn list v1.3.2
├─ [email protected]
│  ├─ graphql-type-json@~0.1.4
│  ├─ graphql@~0.11.7
│  └─ inflection@~1.12.0
├─ [email protected]
├─ [email protected]
│  └─ [email protected]
├─ [email protected]
└─ [email protected]
✨  Done in 0.17s.

Platform versions:

  • node 8.9.1
  • yarn 1.3.2
  • macOS 10.13.2

from graphql-schema-from-json.

acusti avatar acusti commented on May 14, 2024

As a follow-up, I did another test that uses yarn resolutions to make graphql-schema-from-json use the latest version of graphql, 0.12.3 (see this branch in the test repo). Here’s how I set that up in package.json:

{
  "name": "a",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "graphql": "0.12.3",
    "graphql-schema-from-json": "0.0.3"
  },
  "resolutions": {
    "graphql-schema-from-json/graphql": "0.12.3"
  }
}

Looking in node_modules, I confirmed that only one version of the graphql package is installed, v0.12.3, and that graphql-schema-from-json has no nested node_modules, so the resolutions directive worked correctly. In this case, when I run yarn start, I get:

/Users/andrew/Projects/a/node_modules/graphql/jsutils/instanceOf.js:17
      throw new Error("Cannot use " + constructor.name + " \"" + value + "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results.");
      ^

Error: Cannot use GraphQLObjectType "__Directive" from another module or realm.

Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.

https://yarnpkg.com/en/docs/selective-version-resolutions

Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.
    at instanceOf (/Users/andrew/Projects/a/node_modules/graphql/jsutils/instanceOf.js:17:13)
    at isObjectType (/Users/andrew/Projects/a/node_modules/graphql/type/definition.js:112:35)
    at isNamedType (/Users/andrew/Projects/a/node_modules/graphql/type/definition.js:277:32)
    at isSpecifiedScalarType (/Users/andrew/Projects/a/node_modules/graphql/type/scalars.js:126:38)
    at isDefinedType (/Users/andrew/Projects/a/node_modules/graphql/utilities/schemaPrinter.js:59:46)
    at Array.filter (<anonymous>)
    at printFilteredSchema (/Users/andrew/Projects/a/node_modules/graphql/utilities/schemaPrinter.js:69:6)
    at printSchema (/Users/andrew/Projects/a/node_modules/graphql/utilities/schemaPrinter.js:49:10)
    at Object.<anonymous> (/Users/andrew/Projects/a/index.js:23:13)
    at Module._compile (module.js:635:30)
error Command failed with exit code 1.

from graphql-schema-from-json.

konsumer avatar konsumer commented on May 14, 2024

I have the same issue, even when I lock in to the same version of graphql that graphql-schema-from-json uses:

package.json

{
  "name": "tools",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "genSchema": "babel-node genSchema"
  },
  "dependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-3": "^6.24.1",
    "graphql-schema-from-json": "0.0.3",
    "graphql": "~0.11.7"
  },
  "babel": {
    "presets": [
      "env",
      "stage-3"
    ]
  }
}

genSchema.js

import getSchemaFromData from 'graphql-schema-from-json'
import { printSchema } from 'graphql'

const data = {
  posts: [
    { id: 1, title: 'Lorem Ipsum', views: 254, user_id: 123 },
    { id: 2, title: 'Sic Dolor amet', views: 65, user_id: 456 }
  ],
  users: [
    { id: 123, name: 'John Doe' },
    { id: 456, name: 'Jane Doe' }
  ],
  comments: [
    { id: 987, post_id: 1, body: 'Consectetur adipiscing elit', date: new Date('2017-07-03') },
    { id: 995, post_id: 1, body: 'Nam molestie pellentesque dui', date: new Date('2017-08-17') }
  ]
}

// Get the schema as a JSON object
const schema = getSchemaFromData(data)

// Print the GQL for this schema
console.log(printSchema(schema))

ERROR

npm run genSchema

> [email protected] genSchema /Users/konsumer/Desktop/data-server/tools
> babel-node genSchema

/Users/konsumer/Desktop/data-server/tools/node_modules/graphql/jsutils/invariant.js:18
    throw new Error(message);
    ^

Error
    at invariant (/Users/konsumer/Desktop/data-server/tools/node_modules/graphql/jsutils/invariant.js:18:11)
    at printType (/Users/konsumer/Desktop/data-server/tools/node_modules/graphql/utilities/schemaPrinter.js:151:83)
    at Array.map (<anonymous>)
    at printFilteredSchema (/Users/konsumer/Desktop/data-server/tools/node_modules/graphql/utilities/schemaPrinter.js:80:87)
    at printSchema (/Users/konsumer/Desktop/data-server/tools/node_modules/graphql/utilities/schemaPrinter.js:44:10)
    at Object.<anonymous> (/Users/konsumer/Desktop/data-server/tools/genSchema.js:23:13)
    at Module._compile (module.js:662:30)
    at loader (/Users/konsumer/Desktop/data-server/tools/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/konsumer/Desktop/data-server/tools/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:575:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] genSchema: `babel-node genSchema`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] genSchema script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/konsumer/.npm/_logs/2018-03-21T21_53_52_872Z-debug.log

from graphql-schema-from-json.

konsumer avatar konsumer commented on May 14, 2024

schema looks like this:

GraphQLSchema {
  _queryType: Query,
  _mutationType: Mutation,
  _subscriptionType: null,
  _directives:
   [ GraphQLDirective {
       name: 'include',
       description: 'Directs the executor to include this field or fragment only when the `if` argument is true.',
       locations: [Array],
       astNode: undefined,
       args: [Array] },
     GraphQLDirective {
       name: 'skip',
       description: 'Directs the executor to skip this field or fragment when the `if` argument is true.',
       locations: [Array],
       astNode: undefined,
       args: [Array] },
     GraphQLDirective {
       name: 'deprecated',
       description: 'Marks an element of a GraphQL schema as no longer supported.',
       locations: [Array],
       astNode: undefined,
       args: [Array] } ],
  astNode: null,
  _typeMap:
   { Query: Query,
     ID: ID,
     Post: Post,
     String: String,
     Int: Int,
     User: User,
     Comment: Comment,
     Date: Date,
     PostFilter: PostFilter,
     ListMetadata: ListMetadata,
     UserFilter: UserFilter,
     CommentFilter: CommentFilter,
     Mutation: Mutation,
     Boolean: Boolean,
     __Schema: __Schema,
     __Type: __Type,
     __TypeKind: __TypeKind,
     __Field: __Field,
     __InputValue: __InputValue,
     __EnumValue: __EnumValue,
     __Directive: __Directive,
     __DirectiveLocation: __DirectiveLocation },
  _implementations: {} }

from graphql-schema-from-json.

djhi avatar djhi commented on May 14, 2024

No, but you're welcome to investigate too and send a pull request ;)

from graphql-schema-from-json.

fzaninotto avatar fzaninotto commented on May 14, 2024

ping @djhi

from graphql-schema-from-json.

keshann93 avatar keshann93 commented on May 14, 2024

are we having a fix for this issue?

from graphql-schema-from-json.

Related Issues (2)

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.