Search code examples
c#graphqlstrawberryshake

C# GraphQL StrawberryShake Init problems


I am trying to initialize a new graphQL client in Visual Studio 2022 using the StrawberryShake.Tools command:

dotnet graphql init {Endpoint} 

However it always fails with an error

Error HTTP_ERROR: Response status code does not indicate success: 405 (Method Not Allowed)

After a little research and getting little help from the GraphQL server developer, I am running under the assumption that the server simply does not allow this operation and so I cannot use the tool to initialize the client.

If anyone has any information on how I might actually get this tool to work I would love to know. I believe that the GraphQL endpoint requires a bearer token. I also have tried using the --scheme Bearer {Token} option and it returns the same result.

Since It seems I cannot actually use the tool to init the client, I set out to attempt to manually set up the schema and the graphqlrc.json file to see if it will still work.

I was able to pull the Schema text from the server using a manual query provided to me by the developers that built the application. I added the schema.graphql file and the graphqlrc.json file from a template I found online.

After installing the nuget packages and a query.graphql file, I tried various things to get it to auto generate the C# code with a build.

Things I have tried include:

  • Make sure the .graphql file is in the root of the project.
  • Modify the build action on the file properties to GraphQL Compile.

No matter what I try, it does not produce any generated code. I am wondering if there is something I am missing in the process, or is there some other modification that is made when the dotnet graphql init command is run that I am missing in my manual setup.

Does anyone have any ideas for me to try?

I previously described the things I have tried.

The endpoint is wi-fiber.sonar.software/graphiql This is an instance of the cloud application sonar.software which is a cloud CRM IPAM and Inventory Management system aimed at WISPs and FISPs. Here is a link to their documentation of how to consume their API. docs.sonar.expert/system/consuming-the-sonar-api The documentation confirms that it is served by HTTPS and uses only the POST verb.


Solution

  • I eventually ended up talking to one of the application developers who explained that I was using the wrong endpoint. I was using the address of the graphiql web app where you can manually run queries and the endpoint is different. I still am not clear if this is common practice, but it was the simple answer.

    I did get stuck for a minute after correcting the endpoint because it kept giving me an unauthorized 401 response. I was using the --token flag to send my Auth token for the init. The documentation indicates that the default token scheme is Bearer, but I did have to specify it with the --scheme Bearer flag. Once I added that, it went through without any issue.