Skip to content

Allow to override existing schema with GraphQL-faker #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rossoha opened this issue Sep 15, 2021 · 1 comment
Open

Allow to override existing schema with GraphQL-faker #156

rossoha opened this issue Sep 15, 2021 · 1 comment

Comments

@rossoha
Copy link

rossoha commented Sep 15, 2021

At the moment faker doesn't allow to override fields that already on the backend, but there might be a situation when existing API is not yet implemented and return some default value (like null). So it would be nice to have a way to override such a response.

Example error message: Field "User.firstName" already exists in the schema. It cannot also be defined in this type extension.

Example schema from server:

type User {
    _instanceName: String
     id: UUID
    firstName: String
    lastName: String
}

Example extension file content :

extend type User {  
  firstName: String @fake(type: firstName)
}
@joepk90
Copy link

joepk90 commented Apr 29, 2025

If anyone is interested, I looked into this myself as it didn't look like the original creators were going to do this (as it's now been 3 1/2 years since this issue was opened, and 2 years since the last commit):

I forked project, refactored it and made this possible:
https://github.com/joepk90/graphql-faker-refactored/

By default (via the .env.example file) the project extends the following GraphQL API:
https://swapi-graphql.netlify.app/graphql

Example Schema extension to add to the Editor:

extend type Film {
  title: String @examples(values: [
    "The Terminator",
    "Terminator 2: Judgement Day",
    "Terminaator 3: Rise of the Machines"
  ])
  rating: Int @examples(values: [5, 4, 1])
}

Query to use in the GraphQL Playground:

query ExampleQuery {
  allFilms {
    films {
      title
      rating
      director
    }
  }
}

Hope others also find this useful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants