Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL for .Net Error: Unmapped selection Field

I'm just learning .NET Core and GraphQL and can't get a single example from the web (and I've tried a dozen) to work. They're all using this library https://graphql-dotnet.github.io and every time I try to hit the endpoint with a valid GraphQL query I get the following response:

{
    "errors": [
        {
            "message": "Unmapped selection Field",
            "extensions": {
                "code": "EXECUTION_ERROR"
            }
        }
    ]
}

One of the examples: https://github.com/mmacneil/ASPNetCoreGraphQL

I can't seem to find anything googling that error, and there's not much help with the documentation regarding that. I'm hoping for someone who has worked with the library and had the same issues.

This is the error from the result of the query executing in GraphQLController:

InnerException = {GraphQL.ExecutionError: Unmapped selection Field 
at GraphQL.Language.CoreToVanillaConverter.Selection(ASTNode source)
at GraphQL.Language.CoreToVanillaConverter.SelectionSet(GraphQLSelectionSet source) 
at GraphQL.Language.CoreToVanillaConverter.Operation(GraphQLOperationDefinition source) 
at GraphQL.Language.CoreToVanillaConverter.AddDefinitions(GraphQLDocument source, Document target)
at GraphQL.Language.CoreToVanillaConverter.Convert(String body, GraphQLDocument source)
at GraphQL.Execution.GraphQLDocumentBuilder.Build(String body)
at GraphQL.DocumentExecuter.ExecuteAsync(ExecutionOptions options)

This is also my first post here. Let me know if you need more info.

like image 748
Milan Miljus Avatar asked Mar 31 '19 15:03

Milan Miljus


2 Answers

I suspect you have a bad copy of the GraphQL-Parser NuGet package. I have also been having a similar issue and have reported it to the GraphQL-Parser issue tracker.

Try the following (assuming Visual Studio 2017):

  1. Clean your solution, either with Build -> Clean Solution or by downloading a fresh copy of the example solutions.
  2. Close Visual Studio to ensure it is not locking open any files
  3. Clear your NuGet package cache by running dotnet nuget locals http-cache --clear or dotnet nuget locals all --clear from a command prompt.
  4. Re-open your projects and build. It should restore a fresh copy of the packages from the NuGet servers which hopefully won't have these issues.
like image 62
Cameron Avatar answered Sep 21 '22 22:09

Cameron


I experienced this error even inside a simple helloWorld GraphQl sample Console and also in previously cloned projects.

installing(updating) GraphQL-Parser Nuget Package from Version 3 to 4, resolved the problem.

One thing to note is that at first this package is installed as a dependency and in VS 2019 you will not see it as a separated package. But if you install version 4 manually from Nuget package Manager or by Package Manager Console, the one under GraphQL package in Visual Studio Dependency tree will also reference to it.

enter image description here

like image 20
Iman Avatar answered Sep 17 '22 22:09

Iman