DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Byte sized tip: Dart and GraphQL (Flutter and GraphQL)
Chathu Vishwaijith
Chathu Vishwaijith

Posted on

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?

Top comments (0)

πŸ€” Did you know?

Β 
DEV has a variety of tags to help you find the content you like. Find and follow your favorite tags.