Replies: 1 comment 1 reply
-
I like the idea, but I think this would be a good use case for a custom field function, like this: import random
import strawberry
import faker
fake = faker.Faker(locale="fr_FR")
@strawberry.type
class User:
first_name: str = fake_field(factory=fake.last_name)
last_name: str = fake_field(factory=fake.last_name) what do you think? :) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Have you ever played around with Javascript's graphql-faker ?
It's a nice wrapper for schema-first GraphQL APIs that uses directives to generate fake data on the fly, which allows frontend teams to get started on their code without having to wait on their backend team.
Because it relies heavily on directives, it seems unsuitable for code-first frameworks as even rendering directives seems to be something that no code-first GraphQL framework can do (or wants to do for that matter)
I think that using faker would allow Strawberry to do the same thing, with the added benefit that you can also define your own generator on the fly (being a code-first framework) instead of solely relying on existing ones.
I'm thinking of something like this:
Or something even more deeply integrated with the
faker
library:last_name: str = strawberry.field(factory="last_name")
(in which case there is the question of setting a project-wide locale, in some sort of "strawberry settings" or via environment variable)
The idea of using
factory
instead of maybe using dataclasses.field.default_factory is that in production, you don't want an instance that has a missing attribute to be silently created with fake data: hence the idea of removing thedefault
fromdefault_factory
What do you think ? 🍓
Beta Was this translation helpful? Give feedback.
All reactions