-
Notifications
You must be signed in to change notification settings - Fork 184
Description
I am trying to create a mutation to generate a branch protection rule in GitHub.
I have loaded the schema provided by Github as follows:
with open('../input/schema.docs.graphql') as f:
github_schema = f.read()
client = gql.Client(schema=github_schema)
ds = DSLSchema(client.schema)
The record I want to create is held as a dictionary:
{
"pattern": "10.1[!2].0.x/*-Additional",
"allowsDeletions": true,
"allowsForcePushes": false,
"dismissesStaleReviews": false,
"requiredStatusCheckContexts": [
"STG-Upgrade"
],
"requiresStrictStatusChecks": false,
"isAdminEnforced": true,
"repositoryId": "12345"
}
So I try to build the mutation as follows:
mutation = DSLMutation(ds.Mutation.createBranchProtectionRule.args(input=item).select(*args)
I get past the .args method fine. But I am not able to get the select method to complete.
I initially expected that the correct arguments would have been any from this list:
- ds.branchProtectionRule.pattern
- ds.branchProtectionRule.allowsDeletions
and so on....
However, including one or more of these fields generates an exception, saying that "branchProtectionRule" is not in the schema.
Capitalising branchProtectionRule to BranchProtectionRule got me further, but now it tells me that the field (e.g. 'pattern' is invalid):
File "/home/ubuntu/.virtualenv/django/lib/python3.9/site-packages/gql/dsl.py", line 884, in select
super().select(*fields, **fields_with_alias)
File "/home/ubuntu/.virtualenv/django/lib/python3.9/site-packages/gql/dsl.py", line 362, in select
raise GraphQLError(f"Invalid field for {self!r}: {field!r}")
graphql.error.graphql_error.GraphQLError: Invalid field for <DSLField Mutation::createBranchProtectionRule>: <DSLField BranchProtectionRule::pattern>
On debugging the code for "is_valid_field(field)", called from line 361 of dsl.py, I am taken to line 745, which attempts to find the parent_type of the field using the following fragment (line 745 of dsl.py):
parent_type = get_named_type(self.field.type)
Now the field itself ALREADY has an attribute "parent_type" which is 'BranchProtectionRule", and pattern is definitely in the list of allowed fields. However, the value for parent_type that is returned and used by the method is "CreateBranchProtectionRulePayload", which itself has fields of "branchProtectionRule" and "clientMutationId". So now of course pattern is an invalid field so its rejected...
So I think to myself, "OK, lets try following the path given by the parent type", so I change my select args to the form:
ds.CreateBranchProtectionRulePayload.branchProtectionRule.pattern
and now I get the exception "AttributeError: 'DSLField' object has no attribute 'pattern'"
Is this an issue with the schema, gql, or me?