我正在使用graphql_flutter包在flutter中测试一个graphql查询。
下面是我执行查询的代码-
final phoneNumbers = ["4160000000", "7780000000"];
final filters = phoneNumbers.map((phoneNumber) => phoneNumber).toList();
Map<String, dynamic> filter = {
"or": filters,
};
const String getAzureContacts = """
query filterItems (\$filter: filters!) {
items(filter: \$filter) {
items {
partitionKey
userPhoneNumber
userDisplayName
}
}
}
""";
HttpLink link = GlobalVariables().graphqlEndpoint;
GraphQLClient graphQlClient = GraphQLClient(
link: link,
cache: GraphQLCache(
store: InMemoryStore(),
),
);
try {
QueryResult queryResult = await graphQlClient.query(
QueryOptions(
fetchPolicy: FetchPolicy.networkOnly,
document: gql(
getAzureContacts,
),
variables: {'filter': filter}),
);
print(queryResult.data);
} catch (e) {
print('Query failed: $e');
}
下面是运行代码后的错误-
I/flutter ( 7103): Query failed: Error on line 6, column 5: Expected a selection set starting with '{'
I/flutter ( 7103): ╷
I/flutter ( 7103): 6 │ }
I/flutter ( 7103): │ ^
I/flutter ( 7103): ╵
更新-2023年4月22日
我已经添加了花括号,现在我得到另一个错误。
const String getAzureContacts = """ {
query(\$filter: filters!) {
items(filter: \$filter) {
items {
partitionKey
userPhoneNumber
userDisplayName
}
}
}
}
""";
I/flutter (11573): Query failed: Error on line 2, column 22: Expected an argument name
I/flutter (11573): ╷
I/flutter (11573): 2 │ query filterItems ($filter: filters!) {
I/flutter (11573): │ ^
I/flutter (11573): ╵
1条答案
按热度按时间66bbxpm51#
graphql包中的查询与您的不完全相同
注意三个单引号前的“r”和“$”前的“\”
https://pub.dev/packages/graphql#query