Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:查询AWS AppSync_Flutter_Graphql_Aws Appsync - Fatal编程技术网

Flutter 颤振:查询AWS AppSync

Flutter 颤振:查询AWS AppSync,flutter,graphql,aws-appsync,Flutter,Graphql,Aws Appsync,我最近开始使用AWS AppSync和Flatter。我很难把他们联系起来 我使用的是graphql_颤振软件包,还没有弄清楚如何使用它进行查询 下面是我的代码片段: final HttpLink httpLink = HttpLink( uri: 'https://myapi.xyz.com/graphql', ); final AuthLink authLink = AuthLink(

我最近开始使用AWS AppSync和Flatter。我很难把他们联系起来

我使用的是graphql_颤振软件包,还没有弄清楚如何使用它进行查询

下面是我的代码片段:

final HttpLink httpLink = HttpLink(
              uri: 'https://myapi.xyz.com/graphql',
            );


            final AuthLink authLink = AuthLink(
              getToken: () async => 'Bearer ${globals.token}',  
            );

            final Link link = authLink.concat(httpLink);

            GraphQLClient client = GraphQLClient(link: link, cache: InMemoryCache());

            QueryOptions query = QueryOptions(documentNode: gql(queries.getAll));

            var result = await client.query(query);
我得到以下错误:

Error: 'await' can only be used in 'async' or 'async*' methods.
            var result = await client.query(query);  

如何使整个过程正常工作?

在使用异步方法时,需要使用未来函数。您可以更改您的方法,如:


未来的getRepositories(int numOfRepositories)异步{
最终HttpLink HttpLink=HttpLink(
uri:'https://myapi.xyz.com/graphql',
);
最终AuthLink AuthLink=AuthLink(
getToken:()async=>'Bearer${globals.token}',
);
最终链接=authLink.concat(httpLink);
GraphQLClient=GraphQLClient(link:link,cache:InMemoryCache());
QueryOptions query=QueryOptions(documentNode:gql(querys.getAll));
var result=wait client.query(查询);
} 
您可以从中阅读有关异步编程的更多信息


 Future<QueryResult> getRepositories(int numOfRepositories) async {
            final HttpLink httpLink = HttpLink(
              uri: 'https://myapi.xyz.com/graphql',
            );


            final AuthLink authLink = AuthLink(
              getToken: () async => 'Bearer ${globals.token}',  
            );

            final Link link = authLink.concat(httpLink);

            GraphQLClient client = GraphQLClient(link: link, cache: InMemoryCache());

            QueryOptions query = QueryOptions(documentNode: gql(queries.getAll));

            var result = await client.query(query);

           }