javascript graphql schema type by name code example
Example 1: tyepes and field in typegraphql
@ObjectType()
class Recipe {
@Field()
id: string;
@Field()
title: string;
@Field()
ratings: Rate[];
@Field()
averageRating: number;
}
Example 2: graphql nested schema
const StaffType = new GraphQLObjectType({
name: 'Staff',
fields: {
id: {type: GraphQLInt},
name: {type: GraphQLString},
role: {type: GraphQLString},
address: {type: AddressType}
}
})
const AddressType = new GraphQLObjectType({
name: 'Address',
fields: {
street: {type: GraphQLString},
town: {type: GraphQLString}
}
})