Skip to content

Bare minimum GraphQL project with dotnet 6 minimal API and HotChocolate

Notifications You must be signed in to change notification settings

osemeke/graphql-intro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

graphql-intro

Bare minimum GraphQL project with dotnet 6 minimal API and HotChocolate

Steps

  • Install latest version of HotChocolate.AspNetCore
  • Add to container builder.Services.AddGraphQLServer().AddQueryType<Query>();
  • Use app.UseEndpoints(endpoints => { endpoints.MapGraphQL(); }); after app.UseRouting();
  • Run project and navigate to /graphql
  • Javascript client should send post request wrapping payload with JSON.stringify

See Program.cs

using API.GraphQL;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddGraphQLServer().AddQueryType<Query>();

var app = builder.Build();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
    endpoints.MapGraphQL();
});

app.Run();

Sample Javascript client request

$.ajax({url: "http://localhost:9000/graphql",
  contentType: "application/json",type:'POST',
  data: JSON.stringify({ query:`{
	 sayHello(name:"${name}")}`
  }),
  success: function(result) {
	 console.log(JSON.stringify(result))
	 $("#SayhelloDiv").html("<h1>"+result.data.sayHello +"</h1>");
  }
});

About

Bare minimum GraphQL project with dotnet 6 minimal API and HotChocolate

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages