nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: graphql-python/graphene
Pull request #635 (2017-12-20 18:45:24)

Raise better error if type is missing from schema
Current it errors with `AttributeError: 'NoneType' object has no attribute 'graphene_type'` if the type is not in the typemap. This PR improves that error.


Patch:
diff --git a/graphene/types/typemap.py b/graphene/types/typemap.py
index d4a4d15..b2bc4a0 100644
--- a/graphene/types/typemap.py
+++ b/graphene/types/typemap.py
@@ -46,7 +46,10 @@ def resolve_type(resolve_type_func, map, type_name, root, info):
 
     if inspect.isclass(_type) and issubclass(_type, ObjectType):
         graphql_type = map.get(_type._meta.name)
-        assert graphql_type and graphql_type.graphene_type == _type, (
+        assert graphql_type, "Can't find type {} in schema".format(
+            _type._meta.name
+        )
+        assert graphql_type.graphene_type == _type, (
             'The type {} does not match with the associated graphene type {}.'
         ).format(_type, graphql_type.graphene_type)
         return graphql_type


Test patch:
diff --git a/graphene/types/tests/test_typemap.py b/graphene/types/tests/test_typemap.py
index d4170db..c0626a1 100644
--- a/graphene/types/tests/test_typemap.py
+++ b/graphene/types/tests/test_typemap.py
@@ -1,3 +1,4 @@
+import pytest
 
 from graphql.type import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
                           GraphQLField, GraphQLInputObjectField,
@@ -13,7 +14,7 @@ from ..inputobjecttype import InputObjectType
 from ..interface import Interface
 from ..objecttype import ObjectType
 from ..scalars import String, Int
-from ..typemap import TypeMap
+from ..typemap import TypeMap, resolve_type
 
 
 def test_enum():
@@ -232,3 +233,22 @@ def test_objecttype_with_possible_types():
     assert graphql_type.is_type_of
     assert graphql_type.is_type_of({}, None) is True
     assert graphql_type.is_type_of(MyObjectType(), None) is False
+
+
+def test_resolve_type_with_missing_type():
+    class MyObjectType(ObjectType):
+        foo_bar = String()
+
+    class MyOtherObjectType(ObjectType):
+        fizz_buzz = String()
+
+    def resolve_type_func(root, info):
+        return MyOtherObjectType
+
+    typemap = TypeMap([MyObjectType])
+    with pytest.raises(AssertionError) as excinfo:
+        resolve_type(
+            resolve_type_func, typemap, 'MyOtherObjectType', {}, {}
+        )
+
+    assert 'MyOtherObjectTyp' in str(excinfo.value)
Repository: graphql-python/graphene
Pull request #638 (2018-01-05 17:47:13)

Dict or attr default resolver
I've created a `dict_or_attr_resolver` so that you can pass dicts or objects to object types.

I've also set it as the default resolver since I can't think of a downside but let me know if you don't think thats a good idea.

jkimbo: Just found https://github.com/graphql-python/graphql-core/pull/103 which looks related. Not sure where the best place to solve this is? @syrusakbary @jhgg 
ekampf: This looks fine to me. 
I want to fix the build in the master branch before starting to approve and merge PRs.
I'll try to get `master` ready to accept new PRs ASAP

Patch:
diff --git a/graphene/types/resolver.py b/graphene/types/resolver.py
index 888aba8..6a8ea02 100644
--- a/graphene/types/resolver.py
+++ b/graphene/types/resolver.py
@@ -6,7 +6,14 @@ def dict_resolver(attname, default_value, root, info, **args):
     return root.get(attname, default_value)
 
 
-default_resolver = attr_resolver
+def dict_or_attr_resolver(attname, default_value, root, info, **args):
+    resolver = attr_resolver
+    if isinstance(root, dict):
+        resolver = dict_resolver
+    return resolver(attname, default_value, root, info, **args)
+
+
+default_resolver = dict_or_attr_resolver
 
 
 def set_default_resolver(resolver):


Test patch:
diff --git a/graphene/types/tests/test_resolver.py b/graphene/types/tests/test_resolver.py
index 2a15028..a03cf18 100644
--- a/graphene/types/tests/test_resolver.py
+++ b/graphene/types/tests/test_resolver.py
@@ -1,6 +1,7 @@
 from ..resolver import (
     attr_resolver,
     dict_resolver,
+    dict_or_attr_resolver,
     get_default_resolver,
     set_default_resolver,
 )
@@ -36,8 +37,16 @@ def test_dict_resolver_default_value():
     assert resolved == "default"
 
 
+def test_dict_or_attr_resolver():
+    resolved = dict_or_attr_resolver("attr", None, demo_dict, info, **args)
+    assert resolved == "value"
+
+    resolved = dict_or_attr_resolver("attr", None, demo_obj, info, **args)
+    assert resolved == "value"
+
+
 def test_get_default_resolver_is_attr_resolver():
-    assert get_default_resolver() == attr_resolver
+    assert get_default_resolver() == dict_or_attr_resolver
 
 
 def test_set_default_resolver_workd():
Repository: graphql-python/graphene
Pull request #673 (2018-02-17 20:25:15)

Fix bug when setting a Relay ConnectionField to be required
Came across this when setting up Relay Connections in my schema. Worked around it by subclassing ConnectionField but thought I'd contribute the fix upstream.


Patch:
diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py
index aa2eeec..bcd238d 100644
--- a/graphene/relay/connection.py
+++ b/graphene/relay/connection.py
@@ -99,7 +99,10 @@ class IterableConnectionField(Field):
     def type(self):
         type = super(IterableConnectionField, self).type
         connection_type = type
-        if is_node(type):
+        if isinstance(type, NonNull):
+            connection_type = type.of_type
+
+        if is_node(connection_type):
             raise Exception(
                 "ConnectionField's now need a explicit ConnectionType for Nodes.\n"
                 "Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections"
@@ -108,7 +111,7 @@ class IterableConnectionField(Field):
         assert issubclass(connection_type, Connection), (
             '{} type have to be a subclass of Connection. Received "{}".'
         ).format(self.__class__.__name__, connection_type)
-        return connection_type
+        return type
 
     @classmethod
     def resolve_connection(cls, connection_type, args, resolved):
@@ -133,6 +136,9 @@ class IterableConnectionField(Field):
     def connection_resolver(cls, resolver, connection_type, root, info, **args):
         resolved = resolver(root, info, **args)
 
+        if isinstance(connection_type, NonNull):
+            connection_type = connection_type.of_type
+
         on_resolve = partial(cls.resolve_connection, connection_type, args)
         if is_thenable(resolved):
             return Promise.resolve(resolved).then(on_resolve)


Test patch:
diff --git a/graphene/relay/tests/test_connection.py b/graphene/relay/tests/test_connection.py
index 3697888..c206f71 100644
--- a/graphene/relay/tests/test_connection.py
+++ b/graphene/relay/tests/test_connection.py
@@ -1,6 +1,6 @@
 import pytest
 
-from ...types import Argument, Field, Int, List, NonNull, ObjectType, String
+from ...types import Argument, Field, Int, List, NonNull, ObjectType, String, Schema
 from ..connection import Connection, ConnectionField, PageInfo
 from ..node import Node
 
@@ -155,3 +155,23 @@ def test_connectionfield_custom_args():
         'last': Argument(Int),
         'extra': Argument(String),
     }
+
+
+def test_connectionfield_required():
+    class MyObjectConnection(Connection):
+
+        class Meta:
+            node = MyObject
+
+    class Query(ObjectType):
+        test_connection = ConnectionField(MyObjectConnection, required=True)
+
+        def resolve_test_connection(root, info, **args):
+            return []
+
+    schema = Schema(query=Query)
+    executed = schema.execute(
+        '{ testConnection { edges { cursor } } }'
+    )
+    assert not executed.errors
+    assert executed.data == {'testConnection': {'edges': []}}
Repository: graphql-python/graphene
Pull request #788 (2018-07-02 08:26:00)

Enable mutations subclassing
The goal of this PR is to be able to subclass mutations like this:

```
    class BaseMutation(graphene.Mutation):
        class Arguments:
            name = graphene.String()

        def mutate(self, info, **kwargs):
            # do something

    class ChildMutation(BaseMutation):
        class Arguments(BaseMutation.Arguments):
            other_arg = graphene.String()

        def mutate(self, info, **kwargs):
            # do other things
```

Note:
    vars(x).get(key, gettattr(x, key)) is used instead of the
    simpler gettatrr(x, key) for python2.7 compat.
    Indeed python2 and python3 lead to different results for

    class Foo(object):
        def bar(self):
            pass
    getattr(Foo, 'bar')

    # python 2.7 : > unbound method bar
    # python 3.x : > function Foo.bar


Patch:
diff --git a/graphene/utils/props.py b/graphene/utils/props.py
index 67fa8a4..5ef3ba0 100644
--- a/graphene/utils/props.py
+++ b/graphene/utils/props.py
@@ -10,4 +10,6 @@ _all_vars = set(dir(_OldClass) + dir(_NewClass))
 
 
 def props(x):
-    return {key: value for key, value in vars(x).items() if key not in _all_vars}
+    return {
+        key: vars(x).get(key, getattr(x, key)) for key in dir(x) if key not in _all_vars
+    }


Test patch:
diff --git a/graphene/types/tests/test_mutation.py b/graphene/types/tests/test_mutation.py
index 3ecefe2..bc722b4 100644
--- a/graphene/types/tests/test_mutation.py
+++ b/graphene/types/tests/test_mutation.py
@@ -148,3 +148,47 @@ def test_mutation_allow_to_have_custom_args():
     assert field.description == "Create a user"
     assert field.deprecation_reason == "Is deprecated"
     assert field.type == NonNull(CreateUser)
+
+
+def test_mutation_as_subclass():
+    class BaseCreateUser(Mutation):
+
+        class Arguments:
+            name = String()
+
+        name = String()
+
+        def mutate(self, info, **args):
+            return args
+
+    class CreateUserWithPlanet(BaseCreateUser):
+
+        class Arguments(BaseCreateUser.Arguments):
+            planet = String()
+
+        planet = String()
+
+        def mutate(self, info, **args):
+            return CreateUserWithPlanet(**args)
+
+    class MyMutation(ObjectType):
+        create_user_with_planet = CreateUserWithPlanet.Field()
+
+    class Query(ObjectType):
+        a = String()
+
+    schema = Schema(query=Query, mutation=MyMutation)
+    result = schema.execute(''' mutation mymutation {
+        createUserWithPlanet(name:"Peter", planet: "earth") {
+            name
+            planet
+        }
+    }
+    ''')
+    assert not result.errors
+    assert result.data == {
+        'createUserWithPlanet': {
+            'name': 'Peter',
+            'planet': 'earth',
+        }
+    }
Repository: graphql-python/graphene
Pull request #821 (2018-08-29 16:31:55)

Fix grammar in error message


Patch:
diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py
index f23849f..a942c01 100644
--- a/graphene/relay/connection.py
+++ b/graphene/relay/connection.py
@@ -103,7 +103,7 @@ class IterableConnectionField(Field):
 
         if is_node(connection_type):
             raise Exception(
-                "ConnectionField's now need a explicit ConnectionType for Nodes.\n"
+                "ConnectionFields now need a explicit ConnectionType for Nodes.\n"
                 "Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections"
             )
 


Test patch:
diff --git a/graphene/relay/tests/test_connection.py b/graphene/relay/tests/test_connection.py
index 061d6ec..ca43f39 100644
--- a/graphene/relay/tests/test_connection.py
+++ b/graphene/relay/tests/test_connection.py
@@ -138,7 +138,7 @@ def test_connectionfield_node_deprecated():
     with pytest.raises(Exception) as exc_info:
         field.type
 
-    assert "ConnectionField's now need a explicit ConnectionType for Nodes." in str(
+    assert "ConnectionFields now need a explicit ConnectionType for Nodes." in str(
         exc_info.value
     )
Repository: graphql-python/graphene
Pull request #1307 (2021-01-26 14:26:37)

Propagate arguments of relay.NodeField to Field (#1036)
* Propagate name, deprecation_reason arguments of relay.NodeField to Field

* Allow custom description in Node.Field and move ID description to ID argument

* Add test for Node.Field with custom name

* Add tests for description, deprecation_reason arguments of NodeField

* Pass all kwargs from NodeField to Field


Patch:
diff --git a/graphene/relay/node.py b/graphene/relay/node.py
index d9c4c0f..4b324a9 100644
--- a/graphene/relay/node.py
+++ b/graphene/relay/node.py
@@ -48,7 +48,7 @@ class GlobalID(Field):
 
 
 class NodeField(Field):
-    def __init__(self, node, type=False, deprecation_reason=None, name=None, **kwargs):
+    def __init__(self, node, type=False, **kwargs):
         assert issubclass(node, Node), "NodeField can only operate in Nodes"
         self.node_type = node
         self.field_type = type
@@ -57,8 +57,8 @@ class NodeField(Field):
             # If we don's specify a type, the field type will be the node
             # interface
             type or node,
-            description="The ID of the object",
-            id=ID(required=True),
+            id=ID(required=True, description="The ID of the object"),
+            **kwargs
         )
 
     def get_resolver(self, parent_resolver):


Test patch:
diff --git a/graphene/relay/tests/test_node.py b/graphene/relay/tests/test_node.py
index fbce1d5..a0f4060 100644
--- a/graphene/relay/tests/test_node.py
+++ b/graphene/relay/tests/test_node.py
@@ -110,6 +110,17 @@ def test_node_field_custom():
     assert node_field.node_type == Node
 
 
+def test_node_field_args():
+    field_args = {
+        "name": "my_custom_name",
+        "description": "my_custom_description",
+        "deprecation_reason": "my_custom_deprecation_reason",
+    }
+    node_field = Node.Field(**field_args)
+    for field_arg, value in field_args.items():
+        assert getattr(node_field, field_arg) == value
+
+
 def test_node_field_only_type():
     executed = schema.execute(
         '{ onlyNode(id:"%s") { __typename, name } } ' % Node.to_global_id("MyNode", 1)
Repository: graphql-python/graphene
Pull request #1430 (2022-06-24 16:03:16)

feat: add ability to provide a type name to enum when using from_enum


Patch:
diff --git a/graphene/types/enum.py b/graphene/types/enum.py
index 70e8ee8..e5cc50e 100644
--- a/graphene/types/enum.py
+++ b/graphene/types/enum.py
@@ -52,7 +52,10 @@ class EnumMeta(SubclassWithMeta_Meta):
         return super(EnumMeta, cls).__call__(*args, **kwargs)
         # return cls._meta.enum(*args, **kwargs)
 
-    def from_enum(cls, enum, description=None, deprecation_reason=None):  # noqa: N805
+    def from_enum(
+        cls, enum, name=None, description=None, deprecation_reason=None
+    ):  # noqa: N805
+        name = name or enum.__name__
         description = description or enum.__doc__
         meta_dict = {
             "enum": enum,
@@ -60,7 +63,7 @@ class EnumMeta(SubclassWithMeta_Meta):
             "deprecation_reason": deprecation_reason,
         }
         meta_class = type("Meta", (object,), meta_dict)
-        return type(meta_class.enum.__name__, (Enum,), {"Meta": meta_class})
+        return type(name, (Enum,), {"Meta": meta_class})
 
 
 class Enum(UnmountedType, BaseType, metaclass=EnumMeta):


Test patch:
diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py
index 471727c..679de16 100644
--- a/graphene/types/tests/test_enum.py
+++ b/graphene/types/tests/test_enum.py
@@ -328,6 +328,52 @@ def test_enum_resolver_compat():
     assert results.data["colorByName"] == Color.RED.name
 
 
+def test_enum_with_name():
+    from enum import Enum as PyEnum
+
+    class Color(PyEnum):
+        RED = 1
+        YELLOW = 2
+        BLUE = 3
+
+    GColor = Enum.from_enum(Color, description="original colors")
+    UniqueGColor = Enum.from_enum(
+        Color, name="UniqueColor", description="unique colors"
+    )
+
+    class Query(ObjectType):
+        color = GColor(required=True)
+        unique_color = UniqueGColor(required=True)
+
+    schema = Schema(query=Query)
+
+    assert (
+        str(schema).strip()
+        == dedent(
+            '''
+            type Query {
+              color: Color!
+              uniqueColor: UniqueColor!
+            }
+
+            """original colors"""
+            enum Color {
+              RED
+              YELLOW
+              BLUE
+            }
+
+            """unique colors"""
+            enum UniqueColor {
+              RED
+              YELLOW
+              BLUE
+            }
+            '''
+        ).strip()
+    )
+
+
 def test_enum_resolver_invalid():
     from enum import Enum as PyEnum