Byte sized tip: Dart and GraphQL (Flutter and GraphQL)

iamchathu

Chathu Vishwaijith

Posted on May 31, 2022

Byte sized tip: Dart and GraphQL (Flutter and GraphQL)

I have seen in some tutorials and documentations that write GraphQL query or mutation like bellow.

const String _getCustomersQuery = '''
  query Customers(\$name: String) {
   customers(name: \$name){
     id
     name
     address
     telNo
    }
  }
''';
Enter fullscreen mode Exit fullscreen mode

In Dart language tour we can see there is a way to use "raw" strings.

So above query can be written without string escaping like this:

const String _getCustomersQuery = r'''
  query Customers($name: String) {
   customers(name: $name){
     id
     name
     address
     telNo
    }
  }
''';
Enter fullscreen mode Exit fullscreen mode

Looks nice and you can just copy and paste from GraphQL playground or any other tool that you use.

Do you like to get more tips on using GraphQL with Flutter?

💖 💪 🙅 🚩
iamchathu
Chathu Vishwaijith

Posted on May 31, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related