コード例 #1
0
ファイル: HumanType.cs プロジェクト: bolivernoguera/starwars
        public HumanType(StarWarsData data)
        {
            Name = "Human";

            Field <NonNullGraphType <IdGraphType> >("id", "The id of the human.");

            Field(h => h.Name, nullable: false).Description("The name of the human.");

            Field(h => h.Mass, nullable: false).Description("Mass in kilograms, or null if unknown");

            Field <NonNullGraphType <FloatGraphType> >(
                "height",
                arguments: new QueryArguments(
                    new QueryArgument <HeighEnum> {
                Name = "unit", Description = "Height in the preferred unit, default is meters", DefaultValue = LengthUnit.METER
            }
                    ),
                resolve: context => data.GetHeighOrLenght(context.GetArgument <LengthUnit>("unit", LengthUnit.METER), context.Source.Height)
                );


            Field <ListGraphType <CharacterInterface> >(
                "friends",
                resolve: context => data.GetFriends(context.Source)
                );

            Field <ListGraphType <StarShipType> >(
                "starships",
                resolve: context => context.Source.Starships
                );

            Field <NonNullGraphType <ListGraphType <NonNullGraphType <EpisodeEnum> > > >("appearsIn", "Which movie they appear in.");

            Interface <CharacterInterface>();
        }
コード例 #2
0
        public StarShipType(StarWarsData data)
        {
            Name = "Starship";

            Field <NonNullGraphType <IdGraphType> >("id", "The ID of the starship");

            Field(h => h.Name, nullable: false).Description("The name of the starship");

            Field <NonNullGraphType <FloatGraphType> >(
                "length",
                arguments: new QueryArguments(
                    new QueryArgument <HeighEnum> {
                Name = "unit", Description = "Length of the starship, along the longest axis", DefaultValue = LengthUnit.METER
            }
                    ),
                resolve: context => data.GetHeighOrLenght(context.GetArgument <LengthUnit>("unit", LengthUnit.METER), context.Source.Length)
                );
        }