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?

Oldest comments (0)