Comments (9)
@sepehr500 I released support of @example
on objects in 1.4.0
🎉
Thank you for reporting this issue and highlighting inconsistency with values
👍
from graphql-faker.
@sepehr500 Just to be sure, you trying to write something like this?
type Query {
allCourtCases: [CourtCase!]!
@examples(values: [{jurisdiction: "DFT"},{jurisdiction: "FUR"}])
}
type CourtCase {
jurisdiction: String
}
And you want allCourtCases
always return [{jurisdiction: "DFT"},{jurisdiction: "FUR"}]
?
If you don't depend on the exact value you can write something like this:
type CourtCase {
jurisdiction: String @examples(values: ["DFT", "FUR"])
}
If above solution doesn't solve your problem can you please describe your use case in more details?
from graphql-faker.
I am trying to do something like this:
type Query {
allCourtCases: [CourtCase!]!
@examples(values: [[{state: "WASH", capital: "SEA"},{state: "VA", capital: "RMD"}]])
}
type CourtCase {
capital: String
state: String
}
Sometimes I need certain object properties to always appear together. For example, if I have city and a capital property, I may have logic that makes assumptions about about what other fields can be given some other field, so I would like to be able to mock on an object level. Otherwise, the API would return a random combination of values, and this does not always make sense.
from graphql-faker.
@sepehr500 I made @examples
to work on objects.
It was pretty simple, however supporting an array of fixed size is way more complicated.
Not sure if it fully solves your issue, please see example below:
type Query {
allCourtCases: [CourtCase!]!
@examples(values: [
# if this object selected 'name' is always null
{state: "WASH", capital: "SEA", name: null},
# in this case 'name' is faked as usual
{state: "VA", capital: "RMD"}
])
}
type CourtCase {
name: String @fake(type:firstName)
capital: String
state: String
}
Example of possible result:
{
"data": {
"allCourtCases": [
{
"name": null,
"capital": "SEA",
"state": "WASH"
},
{
"name": "Bria",
"capital": "RMD",
"state": "VA"
},
{
"name": null,
"capital": "SEA",
"state": "WASH"
},
{
"name": "Guadalupe",
"capital": "RMD",
"state": "VA"
}
]
}
}
Does it solve your issue?
Or you always need an exact number of elements in the array?
from graphql-faker.
When I was trying this out it was not working. Do you need to define every property on the object for it to work? Will the ones you don't define not fall through to the fake object property definitions?
from graphql-faker.
When I was trying this out it was not working.
I pushed changes to examplesOnObjects a few minutes ago. You can try it there:
npm install
npm start
Do you need to define every property on the object for it to work?
Only properties for which you want fixed values.
Will the ones you don't define not fall through to the fake object property definitions?
By default, they will fall through and would be faked as usual to explicitly prevent this just define the property with null
as the values.
from graphql-faker.
Looks great! Have not had time to try it yet, but I had question. Given that `values' takes an array of objects that match the properties type, would it make more sense to pass in an array of objects into values like I did in my example? That way if you want to mock a single object, the same pattern of an array of objects would work.
from graphql-faker.
Looks great! Have not had time to try it yet
@sepehr500 I pulished experimental NPM package with this change so you only need to run:
npm install -g [email protected]
Can you please test it and If it solves your problem I will include this change into the next release.
Given that `values' takes an array of objects that match the properties type, would it make more sense to pass in an array of objects into values like I did in my example? That way if you want to mock a single object, the same pattern of an array of objects would work.
Didn't fully understand your question can you please provide some examples?
from graphql-faker.
Tried it out, and it works great! Let me rephrase my previous question
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.
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.