1

Recently started implementing GraphQL in .net core 3.1 project. Initially began with GraphQL.NET, which defaults the endpoint to https://localhost:44330/graphql. I eventually removed it and decided to go with Hot Chocolate, which defaults the endpoint to simply https://localhost:44330. I've scoured the internet looking for answers, but have failed so far. How can I configure the endpoint to be (ex:) https://localhost:44330/newname? I am thinking it can be done somewhere in app.UseGraphQL(), but I haven't found anything. Any help would be great.


Ok, I found the setting I completely overlooked: UseGraphQL has two overloads and the first one is "PathString path".

app.UseGraphQL("/newname")

Hope this at least helps another

Briana Finney
  • 1,171
  • 5
  • 12
  • 22

1 Answers1

1

First Step is you need add this code to your GraphQL client Function:

public class MyGraphqlClient
{
    public const string GraphqlAddress = "https://localhost:44330/newname/";

    private readonly HttpClient _httpClient;

    public MyGraphqlClient(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    //...
}

Then you need to register it in the "Startup.cs" After "Services.AddMvc()":

public void ConfigureServices(IServiceCollection services)
    {

        Services.AddMvc()

        services.AddHttpClient<MyGraphqlClient>(x => x.BaseAddress = new Uri(MyGraphqlClient.GraphqlAddress));}
  • Thanks Ali. This will work for other situations, but not what I was looking for here. I just had a feeling that there was a simple config setting available somewhere. I just found my answer (edited above and head shaking low). Thanks again! – Briana Finney Apr 08 '20 at 23:46