I have a GraphQL backend, which was written in NodeJS, through which I can add content via a mutation. The data that gets fed into that mutation is created via a Python script. At the moment I have a dictionary that looks like this:
{
'title': 'ContentTitle',
'description': 'content description',
'active': True,
'chapters': [
{
'title': 'chapter title',
'lessons': [
{
'title': 'lesson title',
'filePath': 'static-resource-path'
},
{
'title': 'lesson title 2',
'filePath': 'static-resource-path2'
}
]
}
]
}
Which I need to turn into a GraphQL query looking like this:
mutation {
addContent(
title: "ContentTitle",
description: "content description",
active: true,
chapters: [
{
title: "chapter title",
lessons: [
{
title: "lesson title",
filePath: "static-resource-path"
},
{
title: "lesson title 2",
filePath: "static-resource-path2"
}
]
}
]
) {
success
}
}
Is there any simple way to turn the dictionary, which generally has the correct format, into the GraphQL string?