DEV Community

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

Posted on

3 3

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay