lib/graphql/schema/object.rb in graphql-1.8.4 vs lib/graphql/schema/object.rb in graphql-1.8.5

- old
+ new

@@ -37,11 +37,17 @@ def authorized_new(object, context) context.schema.after_lazy(authorized?(object, context)) do |is_authorized| if is_authorized self.new(object, context) else - raise GraphQL::UnauthorizedError.new(object: object, type: self, context: context) + # It failed the authorization check, so go to the schema's authorized object hook + err = GraphQL::UnauthorizedError.new(object: object, type: self, context: context) + # If a new value was returned, wrap that instead of the original value + new_obj = context.schema.unauthorized_object(err) + if new_obj + self.new(new_obj, context) + end end end end end @@ -92,10 +98,9 @@ obj_type.name = graphql_name obj_type.description = description obj_type.interfaces = interfaces obj_type.introspection = introspection obj_type.mutation = mutation - fields.each do |field_name, field_inst| field_defn = field_inst.to_graphql obj_type.fields[field_defn.name] = field_defn end