Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Quingsley
Created October 10, 2022 09:39
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/9cb3ca48054576fb832d9c8b88beca3b to your computer and use it in GitHub Desktop.
Save Quingsley/9cb3ca48054576fb832d9c8b88beca3b 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 {
getSections {
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[0].title);
}
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