Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXEC : error GQL: An item with the same key has already been added. Key: JSON

Tags:

c#

graphql

I am following this strawberry shake tutorial in C# console app. All the steps are successfully performed but when I tried to build using dotnet build , it is getting failed with the below error:

EXEC : error GQL: An item with the same key has already been added. Key: JSON [D:\HTH\GraphQL\StrawberryShake_Graphql_client\GraphqlStrawberry\GraphqlStrawberry\GraphqlStrawberry.csproj] C:\Users\Faizan Khan.nuget\packages\strawberryshake.server\13.0.5\build\StrawberryShake.Server.targets(63,5): error MSB3073: The command "dotnet "C:\Users\Faizan Khan.nuget\packages\strawberry shake.server\13.0.5\build..\tools\net6\dotnet-graphql.dll" generate "D:\HTH\GraphQL\StrawberryShake_Graphql_client\GraphqlStrawberry\GraphqlStrawberry" -o "D:\HTH\GraphQL\StrawberryShake_Graphq l_client\GraphqlStrawberry\GraphqlStrawberry\obj\Debug\net6.0\berry" -n GraphqlStrawberry -a md5 -t" exited with code 1. [D:\HTH\GraphQL\StrawberryShake_Graphql_client\GraphqlStrawberry\GraphqlS trawberry\GraphqlStrawberry.csproj]

Build FAILED.

EXEC : error GQL: An item with the same key has already been added. Key: JSON [D:\HTH\GraphQL\StrawberryShake_Graphql_client\GraphqlStrawberry\GraphqlStrawberry\GraphqlStrawberry.csproj] C:\Users\Faizan Khan.nuget\packages\strawberryshake.server\13.0.5\build\StrawberryShake.Server.targets(63,5): error MSB3073: The command "dotnet "C:\Users\Faizan Khan.nuget\packages\strawberry shake.server\13.0.5\build..\tools\net6\dotnet-graphql.dll" generate "D:\HTH\GraphQL\StrawberryShake_Graphql_client\GraphqlStrawberry\GraphqlStrawberry" -o "D:\HTH\GraphQL\StrawberryShake_Graphq l_client\GraphqlStrawberry\GraphqlStrawberry\obj\Debug\net6.0\berry" -n GraphqlStrawberry -a md5 -t" exited with code 1. [D:\HTH\GraphQL\StrawberryShake_Graphql_client\GraphqlStrawberry\GraphqlS trawberry\GraphqlStrawberry.csproj] 0 Warning(s) 2 Error(s)

Here are the steps which i have taken before building the project

  1. create console project .net 6
  2. then i open terminal put dotnet new tool-manifest
  3. dotnet add Demo package StrawberryShake.Server
  4. dotnet graphql init https://web.com/graphql/ -n ConferenceClient -p ./Demo
  5. Added namespace in json file
  6. Make a query
  7. dotnet build command and got above error.
like image 726
Muhammad Faizan Khan Avatar asked Jan 01 '26 19:01

Muhammad Faizan Khan


1 Answers

The underlying issue is related to the .graphqlrc.json configuration file being too open (due to the "any directory" value) once the generated files are created.

What worked for me was to create a sub-directory and place all of the source query files in there.

To give a specific example, I added a "[project root]/client_queries" directory and moved all of the *.graphql query files into this directory.

I then changed the following value for the "documents" element in the .graphqlrc.json configuration file from:

{
  "schema": "schema.graphql",
  "documents": "**\*.graphql",  <-- CHANGED THIS
  "extensions": {
    "strawberryShake": {
      "name": "StrawberryClient",
      "url": "https://example.com/graphql"
    }
  }
}

to the specific directory that holds the source query files:

{
  "schema": "schema.graphql",
  "documents": "client_queries\*.graphql", <-- TO THIS
  "extensions": {
    "strawberryShake": {
      "name": "StrawberryClient",
      "url": "https://example.com/graphql"
    }
  }
}

I rebuilt the solution and this appears to have resolved the referenced error for me. Hopefully this is helpful.

like image 139
jdub Avatar answered Jan 03 '26 23:01

jdub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!