Class DataGenerator


@Component public class DataGenerator extends Object
This sample is not connected to a database : its aim is just to check all the GraphQL schema possibilities, to insure that everything works correctly, from the client to the server.
This class generates the needed data on the fly.
  • Field Details

    • RANDOM

      public static final Random RANDOM
  • Constructor Details

    • DataGenerator

      public DataGenerator()
  • Method Details

    • generateInstance

      public <T> T generateInstance(Class<T> clazzToReturn)
      Generates a new instance of the given class, with all fields containing a random value. If a field is itself a GraphQL Type (and not a Scalar), then all its field are recursively filled.
      Type Parameters:
      T - Any GraphQL type (scalar or not)
      clazz - A class of a Scalar GraphQL type, or a class of a GraphQL type, as defined in a GraphQL schema.
    • generateInstanceList

      public <T> List<T> generateInstanceList(Class<T> clazz, int nbItems)
      Returns a list of instances of the given type. The instances are filled by generateInstance(Class)
      Type Parameters:
      T - Any GraphQL type (scalar or not)
      clazz -
      nbItems - The number of items expected in the returned list