This is a migrated thread and some comments may be shown as answers.

GraphQl set variables

5 Answers 87 Views
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Veteran
Michael asked on 09 Nov 2020, 10:25 AM

My Update query:

export const UPDATE_AUTHOR_QUERY = "mutation UpdateAuthorMutation($Author: AuthorInput!) {" +
    "updateAuthor(input: $author){" +
        "id," +
    "firstName," +<br>  "lastName" +<br>  "}"+<br>  "}";

 

additionalParamsOnUpdate: function(model){       
    return {       
         query: UPDATE_AUTHOR_QUERY,
         variables: model <br>      
    };   
},

 

 

 

5 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
Veteran
answered on 09 Nov 2020, 10:33 AM

my model:

  data: function() {
    return {
      model: {
        id: "id",
        fields: {
          id: { type: "string", editable: false },
          firstName: { type: "string" },
          lastName: { type: "string" }
        }
      }
    }
  }
}

 

following request is send to graphql-server:

{"query":"mutation UpdateAuthorMutation($Author: AuthorInput!) {updateAuthor(input: $author){id,firstName,lastName}}","variables":{"id":"31","firstName":"A5","lastName":"Zz66"}}

 

The graphql server exspects:

{"query":"mutation UpdateAuthorMutation($Author: AuthorInput!) {updateAuthor(input: $author){id,firstName,lastName}}","variables":{"author": {"id":"31","firstName":"A5","lastName":"Zz66"}}}

0
Michael
Top achievements
Rank 1
Veteran
answered on 09 Nov 2020, 10:49 AM

Solved:

additionalParamsOnUpdate: function(model){
        return {
        query: UPDATE_AUTHOR_QUERY,
        variables: {author: model }
      };    
    },

0
Petar
Telerik team
answered on 09 Nov 2020, 12:12 PM

Hi Michael,

Thank you for sharing what has solved the discussed issue in your project! The shared knowledge will surely help someone in the future. 

Based on your last reply, I would assume that the current thread can be closed. I will close it but if you need further assistance, you can reopen the ticket.  

Regards,
Petar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Michael
Top achievements
Rank 1
Veteran
answered on 10 Nov 2020, 02:07 PM

Query:

export const UPDATE_AUTHOR_QUERY = "mutation UpdateAuthorMutation($author: AuthorInput!) {" +
  "updateAuthor(input: $author){" +
  "id," +
  "firstName," +
  "lastName" +
  "}"+
  "}";

additionalParamsOnUpdate: function(model){
        return {
        query: UPDATE_AUTHOR_QUERY,
        variables: {author: model }
      };    
    },

Result:

{"query":"mutation UpdateAuthorMutation($author: AuthorInput!) {updateAuthor(input: $author){id,firstName,lastName}}"

Works fine!

Query: Create

export const ADD_AUTHOR_QUERY = "mutation AddAuthor($firstName: String!, lastName: String!) {" +
  "addAuthor(firstName: $firstName, lastName: $lastName){" +
  "id," +
  "firstName," +
  "lastName" +
  "}"+
  "}";

    additionalParamsOnCreate: function(model) {
      return {
        query: ADD_AUTHOR_QUERY,
        variables: {author: model } 
      };
    },

Result after saveChanges: (not working)

{"query":"mutation UpdateAuthorMutation($author: AuthorInput!) {updateAuthor(input: $author){id,firstName,lastName}}","variables":{"author":{"id":"0","fields":"","firstName":"123","lastName":"234"}}}

Model is alway the same:

 data: function() {
    return {
      model: {
        id: "id",
        fields: {
          id: { editable: false, nullable: true },
          firstName: { type: "string" },
          lastName: { type: "string" }
        }
      }
    }
  }

Any idea out there?

0
Petar
Telerik team
answered on 12 Nov 2020, 01:11 PM

Hi Michael,

Based only on the provided code, I cannot say what is the reason for the additional "fields" property that appears in the result.

Can you provide more context of what you are trying to implement? Which Kendo UI for Vue component do you use? Can you send me a runnable example in which I can reproduce the reported behavior and further investigate what is triggering it? 

Regards,
Petar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Asked by
Michael
Top achievements
Rank 1
Veteran
Answers by
Michael
Top achievements
Rank 1
Veteran
Petar
Telerik team
Share this question
or