graphql-kit / graphql-faker

🎲 Mock or extend your GraphQL API with faked data. No coding required.
MIT License
2.68k stars 225 forks source link

Introduce @value definition for exact values #199

Closed tomasjanicek closed 10 months ago

tomasjanicek commented 10 months ago

I missed one essential thing in the whole implementation, and that is setting the exact values according to the input. In some cases, this makes it impossible to use graphql-faker as a mock only with @fake and @examples directives. So I finished the @value directive, which might help someone else.

how does it work?

for enum value:

enum UserRole {
  STUDENT,
  BUSINESS_STUDENT,
  MANAGER
  BUSINESS_MANAGER,
  ADMINISTRATOR,
  SUPER_ADMINISTRATOR
}

...

type User {
   ...
   roles: [UserRole] @value(values: ["STUDENT", "BUSINESS_STUDENT"])
}

for Boolean or string values

  token: String @value(value: "TOKEN")
  isActive: String @value(value: true)

for other types:

  type FeatureFlag {
     name: String
  }

  featureFlags: [FeatureFlag!] @value(values: [{name: "cookie_banner"}, {name: "espresso"}])