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

Input for mutation type can only bind data in the last field #93

Closed
thangchung opened this issue Mar 8, 2019 · 5 comments
Closed

Input for mutation type can only bind data in the last field #93

thangchung opened this issue Mar 8, 2019 · 5 comments

Comments

@thangchung
Copy link

thangchung commented Mar 8, 2019

I'm not sure if it is a bug or not, but when I created the input type with multiple fields like

input CreateProductInput {
  name: String!
  price: Float!
  imageUrl: String
  desc: String
}

with mutation type

type Mutation {
  createProduct(message: CreateProductInput!): Product!
}
schema {
  query: Query
  mutation: Mutation
}

on the server side, I have created CoolStoreResolvers class

public class CoolStoreResolvers : ResolverMap
{
    public CoolStoreResolvers(ICoolStoreResolverService resolverService)
    {
        
        this["Mutation"] = new FieldResolverMap
        {
            {"createProduct",  resolverService.CreateProductAsync}
        };
    }
}

and CoolStoreResolverService as

public class CoolStoreResolverService : ICoolStoreResolverService
{
    public async Task<IResolveResult> CreateProductAsync(ResolverContext context)
    {
        var input = context.GetArgument<CreateProductRequest>("message");
		
		// do something		

        return await Task.FromResult(As(product));
    }
}

I tested with graphiql with the test data like

mutation createProduct($message: CreateProductInput!) {
  createProduct(message: $message) {
    name
	price
	desc
  }
}

Input variables as below

{
  "message": {
    "name": "product 1",
    "price": 100,
    "desc": "this is product 1"
  }
}

In the code above, I always got only desc field binding data with the string this is product 1, and the rest of fields such as name, price and imageUrl were null.

I have seen the samples folder from this project only have one field for input type as

input InputMessage {
    content: String!
}

Is it because this library could not bind multiple field data for input type?

I used

<PackageReference Include="tanka.graphql" Version="0.3.1" />
<PackageReference Include="tanka.graphql.server" Version="0.3.1" />
@pekkah
Copy link
Owner

pekkah commented Mar 8, 2019

It should work. I'll check it out later.

@pekkah
Copy link
Owner

pekkah commented Mar 8, 2019

It seems to be working on at least on the executor side

public async Task Mutation1()
.

I'll check if the SignalR is somehow messing up the serialization of the input variables.

pekkah added a commit that referenced this issue Mar 8, 2019
@pekkah
Copy link
Owner

pekkah commented Mar 8, 2019

Found the problem and fixed it. Fix will be in latest beta as soon as the builds finish and I can merge the PR.

@pekkah pekkah closed this as completed in 348deea Mar 8, 2019
@pekkah
Copy link
Owner

pekkah commented Mar 8, 2019

Fixed in 0.3.2

@thangchung
Copy link
Author

@pekkah Thank you very much. It works. I can create the inputs at https://github.com/vietnam-devs/coolstore-microservices/blob/master/src/graphql/coolstore.graphql#L10
I made a ref to vietnam-devs/coolstore-microservices#41 for remembering

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

No branches or pull requests

2 participants