I use StrawberryShake 13.9 in ASP.NET Core 8 / C# and want to consume 2 graphql API from 2 different services which I created with Chillicream's excellent HotChocolate workflow.
At client side I have 2 different folders with different *.graphq files and each folder an own '.graphqlrc.json' file.
To receive the schemas from APIs I do calls like dotnet graphql init [...]
. This works well, twice schema.graphql and schema.extensions.graphql are generated in their separate folders.
WHEN I compile it generates both clients ClientX.cs and ClientsY.cs with lots of errors. Compiler complains about double definitions and ambiguities in the clients " like: DbClientX.Client.cs(2089, 26): [CS8646] "IStringOperationFilterInputInfo.IsAndSet" ist mehrfach explizit implementiert. or missing implementations like: DbClientX.Client.cs(1283, 52): [CS0535] "IntOperationFilterInput" implementiert den Schnittstellenmember "IIntOperationFilterInputInfo.IsNltSet" nicht.
The behavior does not happen, if queries don't use filtering + sorting.
Another idea was to bring it to different namespaces but in '.graphqlrc.json' the namespace line "namespace": "Some.Space.ServiceX", does not bring anything at all, the tools absolutely ignore this line (or I didn't understand the meaning of it).
Is someone who is able to use 2 services (queries with filtering, sorting etc.) in one client-app with Chillicream's tools?
Thanks
Most of all attempts were to modify the graphql-config file, but no results.
In order to generate multiple GraphQL clients in the same project using Strawberry Shake, you will need to do the following:
.graphqlrc.json
file for each service, and add a unique namespace for each clientAssume you want to call two GraphQL services, WidgetService
and SprocketService
.
> mkdir ./WidgetService
> cd WidgetService
> dotnet graphql init https://widgets/graphql -n WidgetClient -p ./
> cd ../
> mkdir ./SprocketService
> cd SprocketService
> dotnet graphql init https://sprockets/graphql -n SprocketClient -p ./
Edit ./WidgetService/.graphqlrc.json
{
"schema": "schema.graphql",
"documents": "**/*.graphql",
"extensions": {
"strawberryShake": {
"name": "WidgetClient",
"namespace": "Widgets", <-- add this line
"url": "https://widgets/graphql",
"records": {
"inputs": false,
"entities": false
},
"transportProfiles": [
{
"default": "Http",
"subscription": "WebSocket"
}
]
}
}
}
Edit ./SprocketService/.graphqlrc.json
{
"schema": "schema.graphql",
"documents": "**/*.graphql",
"extensions": {
"strawberryShake": {
"name": "SprocketClient",
"namespace": "Sprockets", <-- add this line
"url": "https://sprockets/graphql",
"records": {
"inputs": false,
"entities": false
},
"transportProfiles": [
{
"default": "Http",
"subscription": "WebSocket"
}
]
}
}
}