Giter Site home page Giter Site logo

mmacneil / aspnetcoregraphql Goto Github PK

View Code? Open in Web Editor NEW
266.0 13.0 123.0 52 KB

Sample project demonstrating a GraphQL service built with ASP.NET Core 2.2, Entity Framework Core and graphql-dotnet.

Home Page: https://fullstackmark.com/post/17/building-a-graphql-api-with-aspnet-core-2-and-entity-framework-core

License: MIT License

C# 100.00%
aspnet-core graphql entity-framework-core graphql-dotnet sql-server

aspnetcoregraphql's People

Contributors

mmacneil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcoregraphql's Issues

Adding player with non-nullable data is allowed!

adding a player with mutation:

mutation ($player: PlayerInput!){
  createPlayer(player: $player){
    id
    name
    birthDate
  }
}

and variables:

{
  "player":{
    "name":"test"
  }
}

creates the player, with no validation for any field.

then reading the player generates the following error:

{
  "data": {
    "player": {
      "name": "test",
      "birthDate": "0001-01-01",
      "birthPlace": null,
      "weightLbs": 0
    }
  },
  "errors": [
    {
      "message": "GraphQL.ExecutionError: Cannot return null for non-null type. Field: birthPlace, Type: String!.\r\n   at GraphQL.Execution.ExecutionStrategy.ValidateNodeResult(ExecutionContext context, ExecutionNode node)\r\n   at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node)",
      "locations": [
        {
          "line": 5,
          "column": 5
        }
      ],
      "path": [
        "player",
        "birthPlace"
      ]
    }
  ]
}

can you add validation please so that bad data can not be saved?

Cannot run

Hi! I cloned the repo and built it using .Net Core SDK 2.2.106. I use Visual Studio 2017, 15.9.11 on Window Server 2012. The solution builds successfully and I see db populated with records. However when I debug I was directed to localhost:56543 with message "This localhost page can’t be found No webpage was found for the web address: http://localhost:56543/". The port 56543 was found on NHLStats.Api project / Properties / launchSettings.json. I tried to send request using Postman but no luck. I am new to GraphQL and suspect this is an IIS issue. What goes wrong here?

Error deleting an entity after adding it

Current build does not allow you to create an entity and then with another mutation delete that entity.

Steps to reproduce:

  1. Create Add Mutation
  2. Create Delete Mutation
  3. Add item
mutation ($day: DayInput!)  {
  createDay(day:$day){
    id
    agendaDay
  }
}

mutation ($day: DayInput!)  {
  createDay(day:$day){
    id
    agendaDay
  }
}

  1. Immediately try and delete
mutation ($dayId: Int!)  {
  deleteDay(dayId:$dayId){
    id
    agendaDay
  }
}

{
  
	"dayId" : "7004"
  
}

I get the following error

{
 "data": {
   "deleteDay": null
 },
 "errors": [
   {
     "message": "There was an error deleting 7004: The instance of entity type 'Day' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.",
     "locations": [
       {
         "line": 2,
         "column": 3
       }
     ],
     "path": [
       "deleteDay"
     ]
   }
 ]
}

I believe this line is the reason

var sp = services.BuildServiceProvider();
services.AddSingleton<ISchema>(new MITSSchema(new FuncDependencyResolver(type =>sp.GetService(type))));

I replaced it with below and it works as expected.

services.AddScoped<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));

Issue with the connectionstring when executing with VSCode

I tried the below using VSCode and got the error related to connectionstring.

I have updated the connectionstring to "NHLStatsDb": "Data Source=.;Initial Catalog=NHLStats;Trusted_Connection=True;MultipleActiveResultSets=true"
On running the command by navigating to the dotnet run command from the root of the \NHLStats.Api folder

I am getting the following error:
Application startup exception: System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction)

I opened the project using VS2017 and found all this works fine.

Any help on this is much appreciated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.