Comments (18)
@ahmedlhanafy Not ATM, it's just a proposed solution.
I will try to find time to implement it this month
from graphql-faker.
I made NPM module based on my PR which enables fields overriding.
If you need this feature in main module, you can subscribe to my PR's notifications and use my fork-module until it gets merged.
https://www.npmjs.com/package/@proscom/graphql-faker
from graphql-faker.
just to use the proxy mode where some data are coming from actual API and some are mocked locally
That's what I want!
# Remote schema
type User {
username: String!
}
# Local schema
extend type User {
# ...some more fields...
username: String! @fake(type: username)
}
Sounds like @override
would work for my use case but I am not sure why I even need to manually specify thatβif it's in the local schema, just override it instead of throwing an error?!
from graphql-faker.
This is unfortunately a deal-breaker for us, I would love to use this package but not being able to return mock data for existing fields is very annoying. Is there any workaround for this nowadays?
from graphql-faker.
@mxstbr Do you want to mock the entire GraphQL API or just to use the proxy mode where some data are coming from actual API and some are mocked locally?
How about @override
directive, e.g.:
extend type Post {
acticle: String! @override @fake(type: lorem, options: {loremSize: paragraphs})
}
Will it work in your use case?
from graphql-faker.
just override it instead of throwing an error?!
@mxstbr In this case, we are changing the behavior of extend
as defined in GraphQL specification and implemented in any other GraphQL tool/lib.
So I don't want to enable this functionality by default.
How about using --override
CLI Flag instead of individually marking fields?
from graphql-faker.
@IvanGoncharov would like to check if you will have time to look at this any soon. Thx
from graphql-faker.
@blackxored I want this tool to be compliant with GraphQL spec and graphql-js
so I can't change how extendSchema
works. We also design extend mode to be used for applying non-breaking changes to existing GraphQL API and your use case is really different from that.
Hower, I have an idea how to accommodate your use case without introducing too much complexity into graphql-faker. In source code we have fakeSchema function that accepts schema and attaches resolvers to it. I can expose it as an NPM package so you would be able to write:
import { fakeSchema } from 'graphql-faker';
import { makeExecutableSchema } from 'graphql-tools';
const typeDefs = `
type User {
id: ID!
firstName: String @fake(type: firstName)
lastName: String @fake(type: firstName)
}
`;
const resolvers = {
User: {
id() {
// ...
}
}
};
const executableSchema = makeExecutableSchema({
typeDefs,
resolvers,
});
// Assing missing resolvers
fakeSchema(executableSchema);
// Pass executableSchema to your server
Will it solve your use case?
from graphql-faker.
Seems we need to keep multiple version of schema in this case, maybe we could added a "patcher" function.
In fact, I've just defined another fake version of the exact same type and append it onto the end of the original schema, and it works...like:
type Post {
id: ID!
article: String!
}
type Post {
id: ID! @fake(type: uuid)
article: String! @fake(type: lorem, options: {loremSize: paragraphs})
}
by the way, I find this "fakeSchema" π solves my issue: #32
from graphql-faker.
Seems we need to keep multiple version of schema in this case, maybe we could added a "patcher" function.
@liuchong All GraphQL tools (including graphql-tools
) I'm aware of will silently ignore unknown directives, so you can safely use one schema.
by the way, I find this "fakeSchema" π solves my issue: #32
Implementing it requires me to switch from custom fork of graphql-js
to official version + a lot of refactoring. I plan to start working on v2.0.0
release next month.
I will ping you after initial refactoring is done so you could help with PR if you have time for it.
from graphql-faker.
@IvanGoncharov Great, thanks!
from graphql-faker.
That sounds great to me!
from graphql-faker.
@IvanGoncharov Are @override
or --override
available ATM?
from graphql-faker.
Maybe I'm misunderstanding significantly π , but why would you want to define new fields via extend that don't exist in your original (remote) schema?
I would think that that main use case for this library is to mock existing schema field data?
π
from graphql-faker.
@adaam2
I'd like to use graphql-faker to mock the api for new features so the front end can implement a feature without all backend work being done. Sometimes new features require adding fields to existing types. For example, after creating a new Course
type, I'd want to add a courses
field to Contact
:
type Course {
id: ID! @fake(type: uuid)
title: String @fake(type: word)
description: String @fake(type: lorem)
}
extend type Contact {
courses: [Course!] @listLength(min: 1, max: 1)
}
from graphql-faker.
@steezeburger fair enough, but i think there's a place for both use cases here :)
from graphql-faker.
Wouaou... this issue was open back in 2017 and there is still no solution?
It's a pretty common use case, judging by the people who interacted on this thread.
I am also looking at the @OverRide or { fakeSchema } solution -
Sincerely
from graphql-faker.
This is exactly my use case as well. Have an existing GraphQL schema from a Hasura instance that I want to use to generate faked seed data to feed into mutations.
from graphql-faker.
Related Issues (20)
- @fake directive doesn't handle datatype values like boolean or array
- CLI command to generate a valid graphQl schema from the faker one HOT 4
- Fix deprecation Warning: faker.random
- faking graphql api using gaphql faker does not seem to query fields by id
- How to use a custom endpoint for fake service
- Faking file uploads/downloads
- Request for ARM docker image
- Allow to override existing schema with GraphQL-faker
- How to fake simple number with a static prefix?
- Interfaces implements Interface HOT 1
- Stuck at "loading" when running graphql-faker, is there a way to see a more detailed log? HOT 1
- Randomized fragment does not trigger new request
- Can we auto-fake without having to specify the faking it in the sdl file ?
- Unknown directive "specifiedBy" HOT 1
- npm package resolution hanging forever HOT 4
- proxy and SDL
- `@deprecated` directive not supported for input field HOT 3
- Cannot instal graphql-faker HOT 9
- support for interface implementing interfaces
- Any alternatives to this package? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-faker.