Skip to content

Instantly share code, notes, and snippets.

@Quingsley
Created October 10, 2022 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quingsley/1c93c953a75bbc70b923914ea6c1c9ad to your computer and use it in GitHub Desktop.
Save Quingsley/1c93c953a75bbc70b923914ea6c1c9ad to your computer and use it in GitHub Desktop.
queries
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() async{
final List<Section> sections = [];
final graphQLQuery = {
'query': '''query {
getSections(courseId: 16) {
id
courseId
topic
orderNum
}
}'''
};
final response = await http
.post(Uri.parse('https://7522-197-232-145-163.eu.ngrok.io'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode(graphQLQuery)
);
final result = jsonDecode(response.body);
final arr = result['data']['getSections'];
print(arr);
arr.forEach((section) => sections
.add(Section(title: section['topic'],
subsections: [],
sectionId: section['id'])
));
print(sections);
}
class Section {
String title;
int sectionId;
List subsections;
Section(
{required this.title,
required this.subsections,
required this.sectionId});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment