Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid requests generated for queries without input variables #7

Open
davjo664 opened this issue Mar 30, 2020 · 2 comments
Open

Invalid requests generated for queries without input variables #7

davjo664 opened this issue Mar 30, 2020 · 2 comments

Comments

@davjo664
Copy link

When generating requests for queries without any variables the query becomes:

static Json request() {
    Json query = R"(
        query Orders(
        ) {
            orders {
                id
                orderNo
            }
        }
    )";
    Json variables;
    return {{"query", std::move(query)}, {"variables", std::move(variables)}};
}

This results in an error when sending the query to my GraphQL API because of the empty variables input query Orders( ) { .... } it should be query Orders { ... }.

Would appreciate if this issue could be solved. 👍

@davjo664
Copy link
Author

Suggested solution in CodeGeneration.cpp:

QueryDocument generateQueryDocument(
        Field const & field, Operation operation, TypeMap const & typeMap, size_t indentation) {
    QueryDocument document;
    auto & query = document.query;
    auto & variables = document.variables;

    auto selectionSet = generateQueryField(field, typeMap, "", variables, indentation + 1);

    query += indent(indentation) + operationQueryName(operation) + " " + capitalize(field.name);

    if (variables.size()) {
        query += "(\n";
        for (auto const & variable : variables) {
            query += indent(indentation + 1) + "$" + variable.name + ": " + graphqlTypeName(variable.type) + "\n";
        }
        query += indent(indentation) + ")";
    }

    query += " {\n";
    query += selectionSet;
    query += indent(indentation) + "}\n";

    return document;
}

@davjo664
Copy link
Author

#8 PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant