I have 2 GraphQL servers + 1 that should stick them into one. I cannot get my head around the Stitching.graphql file and how it works. I tried the tutorials on the Hot Chocolate website and webinars but still no luck.
- Pokemon – is working on its own
schema {
query: PokemonQuery
}
type PokemonQuery {
pokemon: [PokemonModel!]!
}
type PokemonModel {
id: Int!
pokemon: String!
species_id: Int!
height: Float!
weight: Float!
base_experience: Int!
type_1: String!
type_2: String!
hp: Int!
attack: Int!
defense: Int!
special_attack: Int!
special_defense: Int!
speed: Int!
color_1: String!
color_2: String!
color_f: String!
egg_group_1: String!
egg_group_2: String!
url_icon: String!
generation_id: Int!
url_image: String!
}
- Pokemon Images – is working on its own
type Query {
pokemonImage: [PokemonImage!]!
pokemonImageById(id: String!): PokemonImage!
}
type PokemonImage {
id: String!
url: String!
}
I’m trying to stitch those 2 into one.
// Pokemon
builder.Services.AddHttpClient(Pokemon, c => c.BaseAddress = new Uri("https://localhost:7071/api/graphql"));
// Pokemon image
builder.Services.AddHttpClient(PokemonImage, c => c.BaseAddress = new Uri("https://localhost:7074/api/graphql"));
builder
.AddGraphQLFunction()
.AddRemoteSchema(Pokemon, ignoreRootTypes: true)
.AddRemoteSchema(PokemonImage, ignoreRootTypes: true)
.AddTypeExtensionsFromString("type Query { }")
.AddTypeExtensionsFromFile("Stitching.graphql");
Stitching.graphql
type PokemonMasterDTO {
id : String!
}
extend type Query {
pokemonTest: PokemonMasterDTO! @delegate(schema: "PokemonImage", path: "pokemonImageById(id: $fields:id)")
}
schema {
query: Query
}
I cannot figure it out 🙁
{
"errors": [
{
"message": "A field with the name `id` does not exist.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"pokemonTest"
],
"extensions": {
"code": "STITCHING_FLD_NOT_DEFINED"
}
}
]
}
What I would love to have is PokemonModel + PokemonImage
type PokemonMasterDTO {
id: Int!
pokemon: String!
//... rest of the props from PokemonModel
//PokemonImage
url: String!
}