Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get object #166

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

CyrilleFormont
Copy link

Hi guys,

I had a bottleneck trying to achieve the following:

Mutation declaration:
this.Mutation<RegisterAgentInputGraphType, RegisterAgentMutationPayloadGraphType>("register");

Input Graph Type:


public class RegisterAgentInputGraphType : MutationInputGraphType
    {
        public RegisterAgentInputGraphType()
        {
            this.Field<NonNullGraphType<GuidGraphType>>(Constants.Fields.API_KEY);
            this.Field<NonNullGraphType<AgentDetailInputGraphType>>(Constants.Fields.AGENT_DETAILS);
        }
    }

public class AgentDetailInputGraphType : InputObjectGraphType
    {
        public AgentDetailInputGraphType()
        {
            this.Field<NonNullGraphType<StringGraphType>>(Constants.Fields.IP_ADDRESS);
            this.Field<NonNullGraphType<StringGraphType>>(Constants.Fields.NAME);
            this.Field<NonNullGraphType<StringGraphType>>(Constants.Fields.OS);
        }
    }

DTO

 public class AgentDetailDto
    {
        public string IpAddress { get; init; }
        public string Os { get; init; }
        public string Name { get; init; }
    }

Mutation

 public class RegisterAgentMutationPayloadGraphType : MutationPayloadGraphType
    {
        public override object MutateAndGetPayload(MutationInputs inputs, IResolveFieldContext<object> context)
        {
            var apiKey = inputs.GetGuid(Constants.Fields.API_KEY);
            var agentDetails = inputs.Get<AgentDetailDto>(Constants.Fields.AGENT_DETAILS);

            throw new NotImplementedException();
        }
    }

The query

mutation{
  agents{
     register(input:{
      apiKey:"a8aba2e5b2fc4c8486072491a9bf3d11"
       agentDetails:{
        ipAddress:"a"
        name:"a"
        os:"o"
      }
    }){
      clientMutationId
    }
  }
}

I've had the following error message:
System.InvalidCastException : 'Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'Owl.DAL.DTO.AgentDetailDto'.'

I've just created this pull request to convert the dictionary values into the object passed as param

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant