def get_field_by_name(self, name: str) -> GraphQLField: try: object_name, field_name = name.split(".") except ValueError: raise ImproperlyConfigured( "field name must be of the format " "`TypeName.fieldName` got `{}`.".format(name)) try: return self._gql_types[object_name].find_field(field_name) except (AttributeError, KeyError): raise UnknownSchemaFieldResolver( "field `{}` was not found in GraphQL schema.".format(name))
def _register( schema_name: str, where: str, obj: Optional[Union["Directive", "Resolver", "Scalar", "Subscription"]], ) -> None: if not obj: return SchemaRegistry._schemas.setdefault(schema_name, {}).setdefault(where, {}) if obj.name in SchemaRegistry._schemas[schema_name][where]: raise ImproperlyConfigured( "Can't register < %s > to < %s > %s because it's already " "registered" % (obj.name, schema_name, where)) SchemaRegistry._schemas[schema_name][where][obj.name] = obj
def get_field_by_name(self, name: str) -> "GraphQLField": """ Returns the field corresponding to the filled in name. :param name: name of the field with the following format "Parent.field" :type name: str :return: the field corresponding to the filled in name :rtype: GraphQLField """ try: parent_name, field_name = name.split(".") except ValueError: raise ImproperlyConfigured( "field name must be of the format `TypeName.fieldName` got " f"`{name}`.") try: return self.type_definitions[parent_name].find_field(field_name) except (AttributeError, KeyError): raise UnknownSchemaFieldResolver( f"field `{name}` was not found in GraphQL schema.")
def _register( schema_name: str, where: str, obj: Optional[Union["Directive", "Resolver", "TypeResolver", "Scalar", "Subscription", ]], ) -> None: """ Registers an object to the appropriate key of the store linked to the schema name filled in. :param schema_name: name of the schema to which link the object :param where: type of the object which determines the key where to register it :param obj: object to register :type schema_name: str :type where: str :type obj: Optional[ Union[ Directive, Resolver, TypeResolver, Scalar, Subscription, ] ] """ if not obj: return SchemaRegistry._schemas.setdefault(schema_name, {}).setdefault(where, {}) if obj.name in SchemaRegistry._schemas[schema_name][where]: raise ImproperlyConfigured( "Can't register < %s > to < %s > %s because it's already " "registered" % (obj.name, schema_name, where)) SchemaRegistry._schemas[schema_name][where][obj.name] = obj