Reputation: 3774
I am testing out a graphql query in flutter using the graphql_flutter package.
Below is my code executing the query -
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');
}
Here is the error after running the code -
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): ╵
Update - April 22nd 2023
I have added curly braces, now I am getting another error.
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): ╵
Upvotes: 0
Views: 165
Reputation: 167
The query from graphql package isn't exactly like yours
take care of the "r" before the three single quote and "\" before "$"
https://pub.dev/packages/graphql#query
Upvotes: 1