Created with <3 with dartpad.dev.
Created
October 10, 2022 13:14
-
-
Save Jerome-Jumah/1c93c953a75bbc70b923914ea6c1c9ad to your computer and use it in GitHub Desktop.
queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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