javascript - How to send multiline string from graphQL from flutter? - Stack Overflow

I am trying put multiline support in one of the ment section of app and it is not accepting it.the inp

I am trying put multiline support in one of the ment section of app and it is not accepting it.

the input which i put is

Hi
Hello
Hello

and it is showing this error

And this is the code i am writing for the inputfield

             ListTile(
                leading: CircleAvatar(
                  backgroundImage: AssetImage(UIData.pkImage),
                ),
                title:  Container(
                  constraints: BoxConstraints(
                    maxHeight: double.infinity,
                    minHeight: 20,
                  ),
                child: TextField(
                  keyboardType: TextInputType.multiline,
                  minLines: 1,//Normal textInputField will be displayed
                  maxLines: 10,// when user presses enter it will adapt to it
                  decoration: InputDecoration(
                      suffix: IconButton(
                        color: Colors.grey,
                        icon: Icon(Icons.send),
                        onPressed: () {
                          createComment();
                        },
                      ),
                      hintText: 'Leave a Comment....',
                      border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(20.0),
                          borderSide: BorderSide(color: Colors.teal))),
                  controller: mentController,
                ),
                ),
              ),

The problem is with updating the graphQL query and initializing it with String block

String createComments(String postId, var text) {
    return """
mutation{
  createComment(postId: "$postId", 
  data:{
    text: ""$text"",
  }
  ){
    _id
  }
}
"""
;
  }
              

I am trying put multiline support in one of the ment section of app and it is not accepting it.

the input which i put is

Hi
Hello
Hello

and it is showing this error

And this is the code i am writing for the inputfield

             ListTile(
                leading: CircleAvatar(
                  backgroundImage: AssetImage(UIData.pkImage),
                ),
                title:  Container(
                  constraints: BoxConstraints(
                    maxHeight: double.infinity,
                    minHeight: 20,
                  ),
                child: TextField(
                  keyboardType: TextInputType.multiline,
                  minLines: 1,//Normal textInputField will be displayed
                  maxLines: 10,// when user presses enter it will adapt to it
                  decoration: InputDecoration(
                      suffix: IconButton(
                        color: Colors.grey,
                        icon: Icon(Icons.send),
                        onPressed: () {
                          createComment();
                        },
                      ),
                      hintText: 'Leave a Comment....',
                      border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(20.0),
                          borderSide: BorderSide(color: Colors.teal))),
                  controller: mentController,
                ),
                ),
              ),

The problem is with updating the graphQL query and initializing it with String block

String createComments(String postId, var text) {
    return """
mutation{
  createComment(postId: "$postId", 
  data:{
    text: ""$text"",
  }
  ){
    _id
  }
}
"""
;
  }
              
Share Improve this question edited Mar 18, 2021 at 11:24 Yasharth Dubey asked Mar 17, 2021 at 20:26 Yasharth DubeyYasharth Dubey 5095 silver badges19 bronze badges 6
  • Can you please edit your code to add the place where you provide that string? – MrMikimn Commented Mar 17, 2021 at 21:05
  • sure i am adding it @MikiMints – Yasharth Dubey Commented Mar 17, 2021 at 21:08
  • And can you also provide a sample ments object? – MrMikimn Commented Mar 17, 2021 at 21:17
  • it is of a type string – Yasharth Dubey Commented Mar 17, 2021 at 21:24
  • You can use AutoSize text widget and set maximum lines – Aamil Silawat Commented Mar 18, 2021 at 5:45
 |  Show 1 more ment

2 Answers 2

Reset to default 7 +50

I presume you are using flutter_graphql. It is bad practice to generate mutation strings using interpolation. You should use graphql variables for sending data with mutations (And, there is no problem in sending a multi-line string).

Sample:

String createComments(String postId, var text) {
  const createCommentMutation = """
      mutation createComment(\$postId: String, \$ment:String) { 
        createComment(postId: \$postId, 
          data:{
            text: \$ment,
          }
        ){
          _id
        }
      }
  """;

  dynamic _resp = await _graphClient
          .mutate(MutationOptions(
              document: gql(createCommentMutation),
              variables: {
                'postId': postId, //Add your variables here
                'ment':text
              },
          ));

}

The type of \$postId & \$ment should be same as that of in your graphql schema. I have declared them as String on the very first line.

You can find the documentation of the same here

We can use the additional putting of the spaces also

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745234984a4617850.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信