Repository navigation
|
Hello all, I'm trying to wrap my head around the auto-generated schema (against GitHub) to create a mutation to add (and eventually update) a repository branch protection rule. I can't figure out how the data is supposed to be passed in.
class Mutation(sgqlc.types.Type):
...
create_branch_protection_rule = sgqlc.types.Field(
CreateBranchProtectionRulePayload,
graphql_name="createBranchProtectionRule",
args=sgqlc.types.ArgDict(
(
(
"input",
sgqlc.types.Arg(
sgqlc.types.non_null(CreateBranchProtectionRuleInput),
graphql_name="input",
default=None,
),
),
)
),
)class CreateBranchProtectionRulePayload(sgqlc.types.Type):
__schema__ = github_schema
__field_names__ = ("branch_protection_rule", "client_mutation_id")
branch_protection_rule = sgqlc.types.Field(
"BranchProtectionRule", graphql_name="branchProtectionRule"
)
client_mutation_id = sgqlc.types.Field(String, graphql_name="clientMutationId")class BranchProtectionRule(sgqlc.types.Type, Node):
__schema__ = github_schema
__field_names__ = (
"allows_deletions",
"allows_force_pushes",
"blocks_creations",
"branch_protection_rule_conflicts",
"bypass_force_push_allowances",
"bypass_pull_request_allowances",
"creator",
"database_id",
"dismisses_stale_reviews",
"is_admin_enforced",
"matching_refs",
"pattern",
"push_allowances",
"repository",
"required_approving_review_count",
"required_status_check_contexts",
"required_status_checks",
"requires_approving_reviews",
"requires_code_owner_reviews",
"requires_commit_signatures",
"requires_conversation_resolution",
"requires_linear_history",
"requires_status_checks",
"requires_strict_status_checks",
"restricts_pushes",
"restricts_review_dismissals",
"review_dismissal_allowances",
)
...I've tried several iterations but always seem to get a >>> op = Operation(schema.Mutation)
>>> op.create_branch_protection_rule(repository='fjdkslfs', pattern='main', allows_deletions=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/foouser/scratch/tmp/venv/lib/python3.10/site-packages/sgqlc/operation/__init__.py", line 1724, in __repr__
return str(self)
File "/Users/foouser/scratch/tmp/venv/lib/python3.10/site-packages/sgqlc/operation/__init__.py", line 1721, in __str__
return self.__to_graphql__()
File "/Users/foouser/scratch/tmp/venv/lib/python3.10/site-packages/sgqlc/operation/__init__.py", line 1665, in __to_graphql__
args = self.__field__.args.__to_graphql_input__(
File "/Users/foouser/scratch/tmp/venv/lib/python3.10/site-packages/sgqlc/types/__init__.py", line 2488, in __to_graphql_input__
p = self[k]
KeyError: 'repository'If I omit Thoughts? Guidance? Thanks! |
Replies: 1 comment 2 replies
|
@rgajason The GitHub GraphQL API doesn't take class Mutation(sgqlc.types.Type):
...
create_branch_protection_rule = sgqlc.types.Field(
CreateBranchProtectionRulePayload,
graphql_name="createBranchProtectionRule",
args=sgqlc.types.ArgDict(
(
(
"input", # <-------------------- HERE
sgqlc.types.Arg(
sgqlc.types.non_null(CreateBranchProtectionRuleInput),
graphql_name="input",
default=None,
),
),
)
),
)You can always try the mutation using the GitHub GraphQL explorer and then save the "executable document" and ask sgqlc codegen to generate the code for that operation, when doing so declare the operation with variables (
Given your test, you can try with: mutation CreateBranchProtectionRule(
$input: CreateBranchProtectionRuleInput
) {
createBranchProtectionRule(input: $input) {
branchProtectionRule {
id
}
}
}And you can use with EDIT-1: seems there is no query GetRepositoryId($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
id
}
} |
@rgajason The GitHub GraphQL API doesn't take
repositoryargument, instead it takes aninputargument withrepositoryfield, you can check that in their docs or in your own code snippet: