Пример #1
0
        public StarshipGraphType(Swapi api)
        {
            _api = api;

            Name = "Starship";

            Id(p => p.Id);
            Field(p => p.Name);
            Field(p => p.Model);
            Field(p => p.Manufacturer);
            Field(p => p.CostInCredits);
            Field(p => p.Length);
            Field(p => p.MaxAtmospheringSpeed);
            Field(p => p.Crew);
            Field(p => p.Passengers);
            Field(p => p.CargoCapacity);
            Field(p => p.Consumables);
            Field(p => p.HyperdriveRating);
            Field(p => p.MGLT);
            Field(p => p.StarshipClass);

            Connection <PeopleGraphType>()
            .Name("pilots")
            .ResolveAsync(async ctx => await api
                          .GetMany <People>(ctx.Source.Pilots)
                          .ContinueWith(t => ctx.ToConnection(t.Result))
                          );

            Connection <FilmGraphType>()
            .Name("films")
            .ResolveAsync(async ctx => await api
                          .GetMany <Films>(ctx.Source.Films)
                          .ContinueWith(t => ctx.ToConnection(t.Result))
                          );
        }
Пример #2
0
        public StarWarsQuery(Swapi api)
        {
            Name = "StarWarsQuery";

            Connection <FilmGraphType>()
            .Name("films")
            .ResolveApiConnection <Films>(api);

            Connection <PeopleGraphType>()
            .Name("people")
            .ResolveApiConnection <People>(api);

            Connection <PlanetGraphType>()
            .Name("planets")
            .ResolveApiConnection <Planets>(api);

            Connection <SpeciesGraphType>()
            .Name("species")
            .ResolveApiConnection <Species>(api);

            Connection <StarshipGraphType>()
            .Name("starships")
            .ResolveApiConnection <Starships>(api);

            Connection <VehicleGraphType>()
            .Name("vehicles")
            .ResolveApiConnection <Vehicles>(api);
        }
Пример #3
0
        public PlanetGraphType(Swapi api)
        {
            _api = api;

            Name = "Planet";

            Id(p => p.Id);
            Field(p => p.Name);
            Field(p => p.RotationPeriod);
            Field(p => p.OrbitalPeriod);
            Field(p => p.Diameter);
            Field(p => p.Climate);
            Field(p => p.Gravity);
            Field(p => p.Terrain);
            Field(p => p.SurfaceWater);
            Field(p => p.Population);

            Connection <PeopleGraphType>()
            .Name("residents")
            .ResolveAsync(async ctx => await api
                          .GetMany <People>(ctx.Source.Residents)
                          .ContinueWith(t => ctx.ToConnection(t.Result))
                          );

            Connection <FilmGraphType>()
            .Name("films")
            .ResolveAsync(async ctx => await api
                          .GetMany <Films>(ctx.Source.Films)
                          .ContinueWith(t => ctx.ToConnection(t.Result))
                          );
        }
Пример #4
0
        public VehicleGraphType(Swapi api)
        {
            _api = api;

            Name = "Vehicle";

            Id(p => p.Id);
            Field(p => p.Name);
            Field(p => p.Model);
            Field(p => p.Manufacturer);
            Field(p => p.CostInCredits);
            Field(p => p.Length);
            Field(p => p.MaxAtmospheringSpeed);
            Field(p => p.Crew);
            Field(p => p.Passengers);
            Field(p => p.CargoCapacity);
            Field(p => p.VehicleClass);
            Field(p => p.Consumables);

            Connection <PeopleGraphType>()
            .Name("pilots")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <People>(ctx.Source.Pilots)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <FilmGraphType>()
            .Name("films")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Films>(ctx.Source.Films)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );
        }
 public static void ResolveApiConnection <TEntity>(
     this ConnectionBuilder <object> builder,
     Swapi api
     ) where TEntity : Entity
 {
     builder
     .ResolveAsync(async ctx => await api
                   .GetConnectionAsync <TEntity>(ctx.GetConnectionArguments())
                   .ContinueWith(t => ctx.ToConnection(t.Result.Entities, t.Result.TotalCount))
                   );
 }
Пример #6
0
        public FilmGraphType(Swapi api)
        {
            _api = api;

            Name = "Film";

            Id(p => p.Id);
            Field(p => p.Title);
            Field(p => p.EpisodeId);
            Field(p => p.OpeningCrawl);
            Field(p => p.Director);
            Field(p => p.Producer);
            Field(p => p.ReleaseDate);

            Connection <PeopleGraphType>()
            .Name("characters")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <People>(ctx.Source.Characters)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <PlanetGraphType>()
            .Name("planets")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Planets>(ctx.Source.Planets)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <SpeciesGraphType>()
            .Name("species")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Species>(ctx.Source.Species)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <StarshipGraphType>()
            .Name("starships")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Starships>(ctx.Source.Starships)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <VehicleGraphType>()
            .Name("vehicles")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Vehicles>(ctx.Source.Vehicles)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );
        }
Пример #7
0
        public PeopleGraphType(Swapi api)
        {
            _api = api;

            Name = "People";

            Id(p => p.Id);
            Field(p => p.Name);
            Field(p => p.Height);
            Field(p => p.Mass);
            Field(p => p.HairColor);
            Field(p => p.SkinColor);
            Field(p => p.EyeColor);
            Field(p => p.BirthYear);
            Field(p => p.Gender);
            Field(
                name: "homeworld",
                type: typeof(PlanetGraphType),
                resolve: ctx => _api.GetEntity <Planets>(ctx.Source.Homeworld)
                );

            Connection <FilmGraphType>()
            .Name("films")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Films>(ctx.Source.Films)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );


            Connection <SpeciesGraphType>()
            .Name("species")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Species>(ctx.Source.Species)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <StarshipGraphType>()
            .Name("starships")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Starships>(ctx.Source.Starships)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <VehicleGraphType>()
            .Name("vehicles")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Vehicles>(ctx.Source.Vehicles)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );
        }
Пример #8
0
        public StarWarsQuery(Swapi api)
        {
            Name = "StarWarsQuery";

            Connection <FilmGraphType>()
            .Name("films")
            .Resolve(ctx => api
                     .GetConnection <Films>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <PeopleGraphType>()
            .Name("people")
            .Resolve(ctx => api
                     .GetConnection <People>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <PlanetGraphType>()
            .Name("planets")
            .Resolve(ctx => api
                     .GetConnection <Planets>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <SpeciesGraphType>()
            .Name("species")
            .Resolve(ctx => api
                     .GetConnection <Species>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <StarshipGraphType>()
            .Name("starships")
            .Resolve(ctx => api
                     .GetConnection <Starships>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <VehicleGraphType>()
            .Name("vehicles")
            .Resolve(ctx => api
                     .GetConnection <Vehicles>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );
        }
Пример #9
0
        /// <summary>
        /// Calls the Swapi Api requesting all starships.
        /// The request is deserialized into the Model swapi.
        /// Calls to the api keeps happening so we get all the available pages of data from swapi
        /// </summary>
        /// <returns>List of the available starships</returns>
        public async Task <List <StarShip> > GetStarships()
        {
            string           response;
            Swapi <StarShip> swapi = new Swapi <StarShip>();

            starships = new List <StarShip>();
            response  = await http.GetStringAsync("/api/starships");

            swapi = JsonConvert.DeserializeObject <Swapi <StarShip> >(response);
            starships.AddRange(swapi.results);
            while (swapi.next != null)
            {
                response = await http.GetStringAsync(swapi.next);

                swapi = JsonConvert.DeserializeObject <Swapi <StarShip> >(response);
                starships.AddRange(swapi.results);
            }
            ;
            return(starships);
            //return starships;
        }
Пример #10
0
        public SpeciesGraphType(Swapi api)
        {
            _api = api;

            Name = "Species";

            Id(p => p.Id);
            Field(p => p.Name);

            Field(p => p.Classification);
            Field(p => p.Designation);
            Field(p => p.AverageHeight);
            Field(p => p.SkinColors);
            Field(p => p.HairColors);
            Field(p => p.EyeColors);
            Field(p => p.AverageLifespan);
            Field(p => p.Language);
            Field(
                name: "homeworld",
                type: typeof(PlanetGraphType),
                resolve: ctx => _api.GetEntity <Planets>(ctx.Source.Homeworld)
                );

            Connection <PeopleGraphType>()
            .Name("people")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <People>(ctx.Source.People)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <FilmGraphType>()
            .Name("films")
            .Unidirectional()
            .Resolve(ctx => api
                     .GetMany <Films>(ctx.Source.Films)
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );
        }
Пример #11
0
 public GraphQLContext(Swapi api)
 {
     Api = api;
 }
Пример #12
0
        //private readonly Swapi _api;
        public PropertyQuery(IPropertyRepository propertyRepository, Swapi api)
        {
            Field <ListGraphType <PropertyType> >(
                "properties",
                resolve: context => propertyRepository.GetAll());

            Field <PropertyType>(
                "property",
                arguments: new QueryArguments(new QueryArgument <IntGraphType> {
                Name = "id"
            }),
                resolve: context => propertyRepository.GetById(context.GetArgument <int>("id")));


            this.Name        = "Query";
            this.Description = "The query type, represents all of the entry points into our object graph.";


            Connection <PropertyType>()
            .Name("properties")
            .Resolve(ctx => propertyRepository.GetAllProperties()
                     .GetConnection(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <FilmGraphType>()
            .Name("films")
            .Resolve(ctx => api
                     .GetConnection <Films>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <PeopleGraphType>()
            .Name("people")
            .Resolve(ctx => api
                     .GetConnection <People>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <PlanetGraphType>()
            .Name("planets")
            .Resolve(ctx => api
                     .GetConnection <Planets>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <SpeciesGraphType>()
            .Name("species")
            .Resolve(ctx => api
                     .GetConnection <Species>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <StarshipGraphType>()
            .Name("starships")
            .Resolve(ctx => api
                     .GetConnection <Starships>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );

            Connection <VehicleGraphType>()
            .Name("vehicles")
            .Resolve(ctx => api
                     .GetConnection <Vehicles>(ctx.GetConnectionArguments())
                     .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
                     );
            //Connection<FilmGraphType>()
            //   .Name("films")
            //   .Resolve(ctx => api
            //       .GetConnection<Films>(ctx.GetConnectionArguments())
            //       .ContinueWith(t => ConnectionUtils.ToConnection(t.Result, ctx))
            //   );

            //this.Connection<PropertyType>()
            //    .Name("propertiesList")
            //   .Unidirectional()
            //   .Resolve(ctx => )
        }
Пример #13
0
 /// <summary>
 /// Get starships from the API async.
 /// </summary>
 /// <returns>List of @StarsgipModel</returns>
 public static List <StarshipModel> GetStarshipsAsync() => Swapi.GetStarshipsAsync().Result;
Пример #14
0
 public GraphQLController(RequestExecutor executor, Swapi api, StarWarsSchema schema)
 {
     Schema    = schema;
     _api      = api;
     _executor = executor;
 }
Пример #15
0
        public async Task NullSpaceshipURL_ShouldThrowNullSpaceshipShipURLException()
        {
            HerperExtension.StarshipsURL = string.Empty;

            await Assert.ThrowsAsync <CustomExceptions.NullSpaceshipShipURLException>(() => Swapi.GetStarshipsAsync());
        }