Skip to main content

Objects

GraphQL objects allow you to specify a type with a set of fields or properties. Objects can only be outputs in a resolver. Each field can be of any output type.

GraphQL Specification

The Query, Mutation and Subscription types in the schema are specified using GraphQL objects.

final type = objectType(
'ObjectTypeName',
fields: [],
);
  • With code generation
()
()
class Model {
final String stringField;
final int intField;
final List<Model>? optionalModels;

const Model({
required this.stringField,
required this.intField,
required this.optionalModels,
});
}


Future<Model> getModel(Ctx ctx) {

}

This would generate graphql_api.schema.dart


Interfaces

GraphQL Specification

  • inheritFrom

The inheritFrom function in GraphQLObjectType receives an Interface and assigns it's argument as
a super type, now the Object will implement the Interface passed as parameter.