Code Monkey home page Code Monkey logo

graphql-faker's Introduction

GraphQL Faker logo

GraphQL Faker

Build Status npm David David npm docker

Mock your future API or extend the existing API with realistic data from faker.js. No coding required. All you need is to write GraphQL SDL. Don't worry, we will provide you with examples in our SDL editor.

In the GIF below we add fields to types inside real GitHub API and you can make queries from GraphiQL, Apollo, Relay, etc. and receive real data mixed with mock data. demo-gif

How does it work?

We use @fake directive to let you specify how to fake data. And if 60+ fakers is not enough for you, just use @examples directive to provide examples. Use @listLength directive to specify number of returned array items. Add a directive to any field or custom scalar definition:

type Person {
  name: String @fake(type: firstName)
  gender: String @examples(values: ["male", "female"])
  pets: [Pet] @listLength(min: 1, max: 10)
}

No need to remember or read any docs. Autocompletion is included!

Features

  • 60+ different types of faked data e.g. streetAddress, firstName, lastName, imageUrl, lorem, semver
  • Comes with multiple locales supported
  • Runs as a local server (can be called from browser, cURL, your app, etc.)
  • Interactive editor with autocompletion for directives with GraphiQL embedded
  • ✨ Support for proxying existing GraphQL API and extending it with faked data Extend mode diagram

Install

npm install -g graphql-faker

or run it in a Docker container, see Usage with Docker

TL;DR

Mock GraphQL API based on example SDL and open interactive editor:

graphql-faker --open

Note: You can specify non-existing SDL file names - Faker will use example SDL which you can edit in interactive editor.

Extend real data from SWAPI with faked data based on extension SDL:

graphql-faker ./ext-swapi.graphql --extend http://swapi.apis.guru

Extend real data from GitHub API with faked data based on extension SDL (you can get token here):

graphql-faker ./ext-gh.graphql --extend https://api.github.com/graphql \
--header "Authorization: bearer <TOKEN>"

Usage

graphql-faker [options] [SDL file]

[SDL file] - path to file with SDL. If this argument is omitted Faker uses default file name.

Options

  • -p, --port HTTP Port [default: env.PORT or 9002]
  • -e, --extend URL to existing GraphQL server to extend
  • -o, --open Open page with SDL editor and GraphiQL in browser
  • -H, --header Specify headers to the proxied server in cURL format, e.g.: Authorization: bearer XXXXXXXXX
  • --forward-headers Specify which headers should be forwarded to the proxied server
  • --co, --cors-origin CORS: Specify the custom origin for the Access-Control-Allow-Origin header, by default it is the same as Origin header from the request
  • -h, --help Show help

When specifying the [SDL file] after the --forward-headers option you need to prefix it with -- to clarify it's not another header. For example:

graphql-faker --extend http://example.com/graphql --forward-headers Authorization -- ./temp.faker.graphql

When you finish with an other option there is no need for the --:

graphql-faker --forward-headers Authorization --extend http://example.com/graphql ./temp.faker.graphql

Usage with Docker

docker run -p=9002:9002 apisguru/graphql-faker [options] [SDL file]

To specify a custom file, mount a volume where the file is located to /workdir:

docker run -v=${PWD}:/workdir apisguru/graphql-faker path/to/schema.sdl

Because the process is running inside of the container, --open does not work.

Development

npm i
npm run build
npm run start

graphql-faker's People

Contributors

alecrae avatar amacleay avatar antiarchitect avatar archon- avatar aschepis avatar cajames avatar declaneugeneleekennedy avatar donniewest avatar ivangoncharov avatar jameskyburz avatar knidarkness avatar mac2000 avatar niekert avatar nprizal avatar ojczeo avatar pabloszx avatar peteruithoven avatar robvio avatar romanhotsiy avatar sarpere avatar securingsincity avatar timothyjellison avatar vomchik avatar whoaa512 avatar wtgtybhertgeghgtwtg 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-faker's Issues

Allow explicit declaration of @fake and @examples directives in schema

I use an explicit declaration of @fake and @examples directive like this:

directive @examples(
	values: [String!]!
) on FIELD_DEFINITION | SCALAR

directive @fake(
	type: GraphQLFakerFakeTypes!
) on FIELD_DEFINITION | SCALAR

Otherwise, IDEA's GraphQL plugin complains that these directives are unknown.

However, GraphQL faker server returns this error in version 2.0.0-rc2:

{"errors":[{"message":"There can be only one directive named \"fake\".\n\nThere can be only one directive named \"examples\"."}]}

It worked properly in GraphQL faker version 1.9.2 with these declarations. I think they should be allowed to be present in the schema.

Allow specifying a custom path

I use a custom path /api/graphql (for various reasons) for my apps and would like to set the path using a cli flag. I can send a PR.

Add support for returning non random abstract types

I have had a very specific problem: I have an app, which uses interface Card extended by both Debit Card and CreditCard. They are used by DebitAccount and CreditAccount respectively. However when I receive faked CreditCard type for DebitAccount, the app is not built to handle that.

It would be best for me if I could return DebitCard for DebitAccount only, and not to be limited by a random selection from all Card types.

Would there be interest in such functionality? I have already implemented it in my fork, so I can open a PR for it whenever.

Add ability to specify local mock file

First off, this project is amazing. It's extremely useful for bootstrapping an app before the graphql server exists.

The faker methods are extremely useful, but I'm finding myself wishing I could run custom code to generate what I need in certain scenarios.

What if there was something like this

schema.faker.graphql

type JiraIssue {
  id: ID @fake(type: uuid)
  key: String @fake(type: mock, func: "jiraIssue")
}

graphql-faker-mocks.js

// Imagine this function does something more exciting
export const jiraIssue = () => 'ABC-123'

The semantics here might not be great. It could be a separate directive or the parameters could be different. Ultimately the idea is just to be able to custom mocks.

Due to how extend works we can't replace type fields

So I was given this project a first try since I'm building some sort of boilerplate. I already have a schema, with (most) resolvers in place and I wanted to extend this with mock data. I'm assuming this scenario is probably not the goal for this project, but certainly seems like it can be used for it, and yet it can't.
I can't replace fields within the existing types since extendSchema from graphqljs seems to complain. In this case what I'd like is to leave the schema as is, but replace the resolver instead.

Example:
Original schema:

type User {
  id: ID!
  firstName: String
  lastName: String
}

Our fake schema in extend mode:

extend type User {
  firstName: String @fake(type: firstName)
  lastName: String @fake(type: lastName)
}

I would have expected the above syntax to work, and the resolver within it to return me the fake fields. I feel like I'm missing something obvious but if this isn't supported I think it should. I'd be able to help if you can point me in the right direction.

EDIT:
I've done something like this in the past with addMockFunctionsToSchema from graphql-tools but obviously, that one lacks the Faker integration, and it's also hard to do proper relay connections in there. Maybe we could find a way to use it here as a last resort, but I think custom resolvers after leaving the schema in place should be the way to go.

PayloadTooLargeError: request entity too large

Hello,

I have this problem:

graphql-faker_2018-08-23 17-01-26

PayloadTooLargeError: request entity too large
    at readStream (/home/user/.config/yarn/global/node_modules/raw-body/index.js:155:17)
    at getRawBody (/home/user/.config/yarn/global/node_modules/raw-body/index.js:108:12)
    at read (/home/user/.config/yarn/global/node_modules/body-parser/lib/read.js:77:3)
    at textParser (/home/user/.config/yarn/global/node_modules/body-parser/lib/types/text.js:86:5)
    at Layer.handle [as handle_request] (/home/user/.config/yarn/global/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/user/.config/yarn/global/node_modules/express/lib/router/index.js:317:13)
    at /home/user/.config/yarn/global/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/user/.config/yarn/global/node_modules/express/lib/router/index.js:335:12)
    at next (/home/user/.config/yarn/global/node_modules/express/lib/router/index.js:275:10)
    at expressInit (/home/user/.config/yarn/global/node_modules/express/lib/middleware/init.js:40:5)

version: 1.7.0 and 1.7.5
filesize 4100 lines /108K

Someone have any idea what could have happened or how can I fix it?

Thanks!!

Custom error fields are not proxied

In order to handle forms validation I'm going to use additional fields inside regular errors (to mention exact fields and failed validation rules), however looks like additional field are not proxied at all.

For example: original endpoint gives me response:

{
  "errors": [
    {
      "message": "An unknown error occurred.",
      "category": "auth",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "authUser"
      ]
    }
  ],
  "data": {
    "authUser": null
  }
}

e.g. with custom field category, and while proxying same query via faker - just

{
  "data": {
    "authUser": null
  },
  "errors": [
    {
      "message": "An unknown error occurred.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "authUser"
      ]
    }
  ]
}

So my custom category field is lost.

What do you think about proxying complete error?

Dockerfile not build

$ git clone https://github.com/APIs-guru/graphql-faker.git
$ cd graphql-faker
$ docker build -t graphql-faker  .
Sending build context to Docker daemon  4.304MB
Step 1/6 : FROM node:8.8.1-alpine
8.8.1-alpine: Pulling from library/node
b56ae66c2937: Pull complete 
16e68ed80c6a: Pull complete 
4818769bd05b: Pull complete 
Digest: sha256:ab9161b1be7ed90f1bcf8d483ef72f138010054732bb12a3288ec679a41f2226
Status: Downloaded newer image for node:8.8.1-alpine
 ---> 04a3ba95f191
Step 2/6 : MAINTAINER James Kyburz "[email protected]"
 ---> Running in 5d8869c5a605
 ---> 8c406551f0af
Removing intermediate container 5d8869c5a605
Step 3/6 : RUN apk --no-cache add --virtual native-deps   git &&   npm install graphql-faker -g &&  npm cache clean --force &&  apk del native-deps
 ---> Running in 264c7cee5faa
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
ERROR: unsatisfiable constraints:
  native-deps-0:
    masked in: cache
    satisfies: world[native-deps]
  git (missing):
    required by:
The command '/bin/sh -c apk --no-cache add --virtual native-deps   git &&   npm install graphql-faker -g &&  npm cache clean --force &&  apk del native-deps' returned a non-zero code: 2

Read in exported string

faker is awesome, thanks for the work. I tend to have my schema in a template string and export it so it would be great if I could use that file directly then when I edit it in faker it also gets updated directly in my project. Or do you know a way to achieve this already? I was starting to create something similar to this then saw your project. I am happy to do it if you don't have time as makes more sense to contribute to your project then start another.

An example of the file format is

'use strict';

export default `
  type Company {
    # This is the company name
    name: String @fake(type:companyName)
    # A test by Alison
    test: String @fake(type:productCategory)
    industry: String @examples(values: ["IT", "Manufactury", "Medicine", "Media"])
    employees: [Employee!]
  }

  type Employee {
    firstName: String @fake(type: firstName, locale:en_CA)
    lastName: String @fake(type: lastName, locale:en_CA)
    address: String @fake(type:streetAddress, options: { useFullAddress: true })
    subordinates: [Employee!]
    company: Company
  }

  type Query {
    employee(id: ID): Employee
    company(id: ID): Company
    allCompanies: [Company!]
  }
`;

Also did you mean to have 'Manufactury' instead of 'Manufacturing' ?

Amazing project!

This is not an issue exactly. But I just wanted to thank you for building this amazing project that has just saved me many hours!! Thank you!

Extend number of faker items

I love this project!!!

Faker has many more types that can be faked. (for example, Lorem has lots of subtypes like 'slug".) Would be nice to access them with an extensions file.

Looks like there is a config file that can be extended. Going to try that on a fork. Might get to a pull request...

Examples not working with scalar

Schema:

type Query {
  date: Date 
}
scalar Date @examples(values: ["2019-08-18"])

Query:

{
  date
}

Expected result:

{
  "date": "2019-08-18"
}

Actual result:

{
  "date": "<Date>"
}

Broken in version: 2.0.0-rc.6
Worked properly in 1.9.2

Cannot extend Mutation

Hi! We've been struggling with this for quite a while now, so thought I'd try and ask for help.

Our use-case is simple. Extend an existing schema, and implement new Mutations and Queries. While extending the original Query type works perfectly fine for us, as soon as we try extending the original Mutation type, we get strange errors, possibly related to how the merge is being done and the resulting AST parsed / constructed. Please note we only get this result when using variables; sending hard-coded values works just fine.

We have done some investigation and it appears that the culprit is this method https://github.com/APIs-guru/graphql-faker/blob/master/src/proxy.ts#L122. Unfortunately, this is where we run out of depth, as we currently don't have the bandwidth to study the visit method / API properly.

If anyone here has enough insight on this, it would be awesome if you could help us out. Any input and / or advice is greatly appreciated :)

Our "extend"

type Car {
  id: String @fake(type: uuid)
  ownerName: String @fake(type: fullName)
}

input NewCarInput {
  ownerName: String!
}

extend type Mutation {
  createCar(input: NewCarInput!): Car!
}

Our mutation

mutation CreateCar($input: NewCarInput!) {
  createCar(input: $input) {
    id
  }
}

Result

{
  "errors": [
    {
      "message": "400 Bad Request\n{\"errors\":[{\"message\":\"Unknown type \\\"NewCarInput\\\". Did you mean ... ?\",\"locations\":[{\"line\":1,\"column\":28}]},{\"message\":\"Variable \\\"$input\\\" is never used in operation \\\"CreateCar\\\".\",\"locations\":[{\"line\":1,\"column\":20}]}]}"
    }
  ]
}

Customer scalar input bug

Hey first off, thanks for the awesome work! We've been wanting to do GraphQL First development for a while and your project is definitely a game changer in our workflows!

A bug must have been introduced between 1.2.1 and 1.2.2, I have a query that works with 1.2.1 and not 1.2.2. Here is the (formatted) error returned:

{
  errors: [
    {
      message:
        'Variable "$input" got invalid value {"endDate":"2017-09-03","startDate":"2017-08-28","brandIds":[],"displayDefinitionIds":[],"regions":[],"retailerIds":[],"storeIds":[],"layerGroupingSets":[],"attributeValueSets":[]}.\nIn field "startDate": Expected type "Date", found "2017-08-28".\nIn field "endDate": Expected type "Date", found "2017-09-03".',
      locations: [{ line: 1, column: 64 }]
    }
  ]
};

our schema contains this line:

scalar Date

Expose a JS API (for use within Node.JS / browser?)

This tool would be super-useful inside tests, but it currently requires starting a HTTP server - which is not ideal.

If the API provided a way to provide a seed to the randomness, it would allow for the predictability required in tests

Specify number of items in array

Would it be possible to add the ability to specify the number of items in a list? I would imagine being able to enter a min number and max number then it returns a random number of items within that range. If the numbers are the same then obviously it just returns that number. An example of syntax is below but you might have a better idea.

image

tsc failure "Argument of type '{}' is not assignable to parameter of type 'GraphQLType'"

When I run npm run build:typescript I get the following failure:

> [email protected] build:typescript /Volumes/data/code/graphql-faker
> tsc

src/fake_schema.ts:78:24 - error TS2345: Argument of type '{}' is not assignable to parameter of type 'GraphQLType'.
  Type '{}' is not assignable to type 'GraphQLNonNull<any>'.
    Property 'ofType' is missing in type '{}'.

78     if (isAbstractType(type))
                          ~~~~


src/fake_schema.ts:79:12 - error TS2339: Property 'resolveType' does not exist on type '{}'.

79       type.resolveType = (obj => obj.__typename);
              ~~~~~~~~~~~


npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build:typescript: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build:typescript 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/micro/.npm/_logs/2018-04-25T17_22_20_225Z-debug.log

I don't know much about typescript or graphql, but it seems type is of type {} from Object.values() on line 70 of src/fake_schema.ts. I wonder if there is a way to cast it or something.

Support alternate way to provide examples

Current style of providing example values through annotations have some serious limitations:

  • As the examples are tightly bound with the schema definition, it is not possible to use schema files generated by another tools.
  • Sometimes constraints for fake data would be useful (and by my opinion should be defined along with the examples). For example, in our GQL API we receive an array of objects from server, where all object should have a unique key value.
  • Latest version of GraphQL plugin in PHPStorm is completely broken when using a schema file with @examples annotations.

A programmatical way of providing examples or generating fake data using some constraints would be very useful. Or, isn't there some undocumented way how to do that with current version?

[Feature proposal] Configuration files using cosmiconfig

This is not an issue report but a proposal for the implementation of configuration files.

What would you think of adding cosmiconfig so that we could configure graphql-faker using either:

  • a package.json property
  • a JSON or YAML, extensionless "rc file"
  • an "rc file" with the extensions .json, .yaml, or .yml.
  • a .config.js CommonJS module

In my use case, I see the benefits of using a .config.js file so that I can use my project config file to avoid duplication e.g for the extend url.

Let me know if this is something you would consider for graphql-faker and I would be happy to implement it!

[Dev issue] Can't resolve '../fake_definition' in '/path/to/repo/graphql-faker/src/editor'

first of all, thank you for creating such a amazing project.

this is an issue about development, when i execute npm run build:all, i got some error message:

ERROR in ./index.tsx
Module not found: Error: Can't resolve '../fake_definition' in '/path/to/repo/graphql-faker/src/editor'
 @ ./index.tsx 28:24-53
 @ multi ./index.tsx

ERROR in [at-loader] ./index.tsx:9:42
    TS2307: Cannot find module '../fake_definition'.
Child extract-text-webpack-plugin:

and when open the src/index.ts and src/editor/index.tsx,also get same error.

is something i am missing?

Very cool!

Awesome job guys, this is a super cool tool! πŸ‘

Add tests

Probably fixture tests will be enough:

  • All possible values of @fake
  • Interfaces and Unions
  • List and Non-Null wrappers
  • Relay mutations

And some special tests for extend mode:

  • Aliases in query
  • Fragments in query

Support block comments in IDL

I'm mocking a schema from Prisma which includes block comments like:

  """
  The subscription event gets only dispatched when all of the field names included in this list have been updated
  """
  updatedFields_contains_every: [String!]

but graphql-faker seems to dislike the """ format comments, complaining:

Syntax Error GraphQL (147:3) Expected Name, found String 146: 147: """ ^ 148: The subscription event gets only dispatched when all of the field names included in this list have been updated

Would it be possible to support schemas with this style of comments, so I can easily deploy graphql-faker using only the schema from my repo?

Query-batching doesn't work

Hi, does this graphql-faker "middleware" support query-batching?

I always get an error that the input JSON is invalid 😞

Relationships (ie ID)

Is there anyway to mock relationships? We have a use case where two seperate queries have an ID field, which in our production implementation actually would be the same, and we do some transformative work to lookup by matching IDs.

ie.

{ field: 'thing1', id: 22 }
{ link: '22', id: 22 }

Currently faker randomizes IDs, but there seems to be no way to specify if a relationship should exist so that we can develop against "sane" faked data.

Hopefully that's clear enough, wondering if there is a solution for this kind of scenario.

Inline SDL descriptions causes errors

GraphQL SDL now supports inline descriptions as documentation (http://facebook.github.io/graphql/draft/#sec-Descriptions), but this throws errors in the editor.

This looks to be an issue with the fork and branch (https://github.com/apis-guru/graphql-js/tree/directives-fork-dist) that graphql-faker relies on in https://github.com/APIs-guru/graphql-faker/blob/master/package.json#L48).

Currently that branch is > 500 commits behind. Is there anything preventing this from being updated to the latest?

How to specify options for Float type

I need to generate negative float type from -10.0 to -0.1 I can see there is an options thing

https://github.com/APIs-guru/graphql-faker/blob/master/src/fake.ts#L22

But not sure what type to use how to pass min and max.

By looking in to https://github.com/APIs-guru/graphql-faker/blob/master/src/fake_definition.graphql I tried to go with type: money but it is eventually does not work returning always 0

neg: Float @fake(type: money, options: { minMoney: -10, maxMoney: -0.1 })

If I go just like neg: Float @fake(options: { min: -5, max: -0.1 }) that does not work as type is requited.

Any thoughts?

Ability to fake array of objects

I would like the ability to fake an array of objects. For example,
@examples(values: [{jurisdiction: "DFT"},{jurisdiction: "FUR"}])

The source code made is seem like this is possible. How are you supposed to do it?

How to get a random value from an ENUM?

Hi!

I would like to fake the following type field:

type Phone {
  type: PhoneType @fake(???????????????)
  ...
}

enum PhoneType {
  HOME
  MOBILE
}

And I was wondering if your library is able to randomly choose one value of the ENUM without me writing anything? Or should I have to write:

  type: PhoneType @examples(values: ["HOME", "MOBILE"])

Thank you,

Problems with error handling when extending external API

So as an example, I have something like this.

graphql-faker -p 3002 -e https://myapi.tld/graphql

And a query like this:

query ValidateEmail($email: String!) {
  validateEmail(email: $email)
}

This query can either return this result:

{
  "data": {
    "validateEmail": true
  }
}

Or in the error case, something like this:

{
  "errors": [
    {
      "message": "20006",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "validateEmail"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: 20006",
            "    at CustomerResolver.<anonymous> (/app/dist/customer/customer.resolver.js:55:27)",
            "    at Generator.next (<anonymous>)",
            "    at fulfilled (/app/dist/customer/customer.resolver.js:16:58)",
            "    at process._tickCallback (internal/process/next_tick.js:68:7)"
          ]
        }
      }
    }
  ],
  "data": null
}

Now the problem seems that graphql-faker can't handle the error response. Apollo Client gives you something like that:

[frontend] 10:32:47 [GraphQL error]: Message: Cannot return null for non-nullable field Query.validateEmail., Location: [object Object], Path: validateEmail
[frontend] 10:32:47 [Network error]: ServerError: Response not successful: Received status code 500

Which only appears when using graphql-faker in between to extend the real API. Is there any solution to this?

Add option to reflect CORS origin

Currently, graphql-faker only handles a subset of available CORS options.

It should be possible to start graphql-faker such that the Access-Control-Allow-Origin header reflects the origin of the caller, no matter which caller it is.

Editor build fails

Hi guys,

This is a very nice and handy tool for the development. I would like to extend it with some more fake types though, but I receive the typescript errors during the build npm run build:all.

Also, the documentation suggests using npm install while you got yarn.lock committed into the project repository, which is confusing. And the editor folder doesn't contain either package-lock.json or yarn.lock. I would appreciate if you could add the lock file for the editor as well in order to eliminate any possible issues I might have encountered related to the packaging versions.

The error stack trace:

added 979 packages in 15.151s

> @ build /[project-folder]/src/editor
> webpack -p --config webpack.config.js


[at-loader] Using [email protected] from typescript and "tsconfig.json" from /[project-folder]/src/editor/tsconfig.json.


[at-loader] Checking started in a separate process...

[at-loader] Checking finished with 176 errors
Hash: 2196443f6786388e3987
Version: webpack 2.7.0
Time: 11678ms
       Asset      Size  Chunks                    Chunk Names
     main.js    686 kB       0  [emitted]  [big]  main
    main.css   43.5 kB       0  [emitted]         main
 main.js.map    702 kB       0  [emitted]         main
main.css.map  74 bytes       0  [emitted]         main
   [8] ./~/react/react.js 56 bytes {0} [built]
   [9] ./~/graphql/index.js 17.1 kB {0} [built]
 [143] ./~/react-dom/index.js 59 bytes {0} [built]
 [170] ./index.tsx 9.97 kB {0} [built]
 [171] ./GraphQLEditor/GraphQLEditor.tsx 10 kB {0} [built]
 [172] ./icons.tsx 3.41 kB {0} [built]
 [173] ./~/classnames/index.js 1.1 kB {0} [built]
 [188] ./GraphQLEditor/editor.css 41 bytes {0} [built]
 [189] ./css/app.css 41 bytes {0} [built]
 [190] ./css/codemirror.css 41 bytes {0} [built]
 [191] ./~/graphiql/graphiql.css 41 bytes {0} [built]
 [219] ./~/graphiql/dist/index.js 307 bytes {0} [built]
 [245] ./~/isomorphic-fetch/fetch-npm-browserify.js 233 bytes {0} [built]
 [250] ./~/raw-loader!../fake_definition.graphql 3.05 kB {0} [built]
 [327] multi ./index.tsx 28 bytes {0} [built]
    + 313 hidden modules

ERROR in [at-loader] ./index.tsx:255:17
    TS2345: Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any>'.
  Types of property 'type' are incompatible.
    Type 'string | ComponentClass<any> | StatelessComponent<any>' is not assignable to type 'string | StatelessComponent<any> | ComponentClass<any>'.
      Type 'ComponentClass<any>' is not assignable to type 'string | StatelessComponent<any> | ComponentClass<any>'.
        Type 'React.ComponentClass<any>' is not assignable to type 'React.ComponentClass<any>'. Two different types with this name exist, but they are unrelated.
          Type 'React.Component<any, React.ComponentState>' is not assignable to type 'React.Component<any, React.ComponentState>'. Two different types with this name exist, but they are unrelated.
            Types of property 'render' are incompatible.
              Type '() => ReactNode' is not assignable to type '() => false | Element | null'.
                Type 'ReactNode' is not assignable to type 'false | Element | null'.
                  Type 'undefined' is not assignable to type 'false | Element | null'.

ERROR in [at-loader] ./node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3447:13
    TS2403: Subsequent variable declarations must have the same type.  Variable 'a' must be of type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>', but here has type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>'.

ERROR in [at-loader] ./node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3448:13
    TS2403: Subsequent variable declarations must have the same type.  Variable 'abbr' must be of type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>', but here has type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.

ERROR in [at-loader] ./node_modules/@types/react-dom/node_modules/@types/react/index.d.ts:3449:13
    TS2403: Subsequent variable declarations must have the same type.  Variable 'address' must be of type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>', but here has type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.

What was the changes in the graphql branch?

Hello, I forked this branch for the use here in the company and I decided to use apollo-server instead of graphql-express.

The reason is that we use batched queries and apollo-server has this feature out of the box.

So I saw that you forked the graphql repositorie to implement some changes related to the directives.

github:apis-guru/graphql-js#directives-fork-dist

However I can't find this branch in the forked repo to see what were the changes.

I think the changes was to create/overwrite directives but now graphql provide new feature to do that: https://www.apollographql.com/docs/graphql-tools/schema-directives.html

And thats how I want to approach, but I need to know the changes that you made to continue with this :)

Failing to extend

First of all - awesome project!

I wish to extend my project graphql api, add additional types, and test the client. Im not sure I understand how extend works here.

First of all I was following the gif animation in the readme, I've extended github api, and I have the following in the schema just like in that gif

extend type User {
  petImage: String @fake(type:imageUrl, options: { imageCategory:cats })
}

once I try to save, it prompts me with "Must provide schema definition with query type or a type named Query."

So I thought to add a Query type

extend type User {
  petImage: String @fake(type:imageUrl, options: { imageCategory:cats })
}


type Query {
  user: User
}

then it fails to save again and prompts me with "Type "User" not found in document."

What am I missing here?

Forward-headers and provided headers.

Hi, first of all, this package is AWESOME.

However, we have a problem to make it works with AWS AppSync.
The problem is, that AppSync will deny all connections without Authorization header. So, we created a small script, which will obtain a JWT from AWS and then starts graphql-faker with that token.

Until this, everything is ok. Then when our web client tries to access a graphql-faker's endpoint, it also provides a different JWT as you can be logged in as any user. However, faker will access an AppSync with a JWT provided at start.

In another words:
Is it possible to provide a --header "Authorization: IDTOKEN" alongside with --forward-headers and force graphql-faker to use a provided Authorization header or forward Authorization header when it is provided by client.

We are using this command to start it:

graphql-faker --forward-headers Authorization --header "Authorization: IDTOKEN" --extend https://abc.amazonaws.com/graphql ./ext-dev.graphql

passwordLength option typo

I believe there is a typo in the passwordLength option for the password type. It says passwordLenth without the g.

Arguments order issue?

The Readme mentions:

graphql-faker [options] [IDL file]

But GraphQL-faker only seems to accept the file when it's specified before the other options. So this works:

graphql-faker ./temp.faker.graphql --extend http://localhost:8091/graphql --forward-headers Authorition 

This doesn't work:

graphql-faker --extend http://localhost:8091/graphql --forward-headers Authorition ./temp.faker.graphql

Is there any way to have it also accept the file when it's defined after the options? The benefit would be that it becomes possible to create an npm script and pass in a specific file as argument.

Could we use positional for this?
Could we allow specifying it as a explicit --file option?

Values from @example should be used as exact values

Reported by @sepehr500 in #25

Currently, if want to fake a string, I do the following

type CourtCase {
  jurisdiction: String @examples(values: ["DFT", "FUR"])
}

This makes the think that values expects it's value to be an array of whatever the property type is. So it would follow, that if the type was the following,

type CourtCase {
  jurisdiction: [String] @examples(values: [["DFT", "FUR"],["DFS","DNA"])
}

Since the property type is now an array of strings, it would make sense to pass in an array of strings into the array to match the return type. So if we take this same logic an apply it to Objects, then we would expect a property that has a type that is an array of objects, to look like the following,

type Query {
  allCourtCases: [CourtCase!]!
     @examples(values: [[{state: "WASH", capital: "SEA"},{state: "VA", capital: "RMD"}], [{state:"VA"}]])
}

This way, you have a consistent rule that values always expects an array of whatever type the return type of the property is.

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.