Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gql query as string instead of the internal dsl #2

Merged
merged 4 commits into from
Jul 20, 2017

Conversation

hourliert
Copy link
Member

@hourliert hourliert commented Jul 20, 2017

Fixes #1 .

Caveats:

  • How to handle GraphQL aliases properly?

Sample of code:

  final client = new Client();
  final logger = new Logger('GraphQLClient');
  final graphQLClient = new GraphQLClient(
    client: client,
    logger: logger,
    endPoint: endPoint,
  )..loadSchema(GithubGraphQLSchema);

  //language=GraphQL
  String gqlQuery = '''
    query {
      viewer {
        avatarUrl(size: 200)
        login
        bio @include(if: false)
        gists(first: 5) {
          nodes {
            ...ShortGist
          }
        }
      }
    }
    
    fragment ShortGist on Gist {
      name
      description
    }
  ''';

  var res = await graphQLClient.execute<GithubGraphQLSchema>(
    gqlQuery,
    headers: {'Authorization': 'bearer $apiToken'},
  );

  print(res.viewer.avatarUrl.value);
  print(res.viewer.gists.nodes.first.name.value);

@hourliert hourliert self-assigned this Jul 20, 2017
@hourliert hourliert changed the title Use gql query as string instead of the internal dsl. Use gql query as string instead of the internal dsl Jul 20, 2017
@hourliert hourliert merged commit 38276e0 into master Jul 20, 2017
@hourliert hourliert deleted the refactor/gql_as_string branch July 20, 2017 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant