1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
|
# frozen_string_literal: true
# Here's the "application"
module Jazz
module Models
Instrument = Struct.new(:name, :family)
Ensemble = Struct.new(:name)
Musician = Struct.new(:name, :favorite_key)
Key = Struct.new(:root, :sharp, :flat) do
def self.from_notation(key_str)
key, sharp_or_flat = key_str.split("")
sharp = sharp_or_flat == "♯"
flat = sharp_or_flat == "♭"
Models::Key.new(key, sharp, flat)
end
def to_notation
"#{root}#{sharp ? "♯" : ""}#{flat ? "♭" : ""}"
end
end
def self.reset
@data = {
"Instrument" => [
Models::Instrument.new("Banjo", :str),
Models::Instrument.new("Flute", "WOODWIND"),
Models::Instrument.new("Trumpet", "BRASS"),
Models::Instrument.new("Piano", "KEYS"),
Models::Instrument.new("Organ", "KEYS"),
Models::Instrument.new("Drum Kit", "PERCUSSION"),
],
"Ensemble" => [
Models::Ensemble.new("Bela Fleck and the Flecktones"),
Models::Ensemble.new("Robert Glasper Experiment"),
Models::Ensemble.new("Spinal Tap"),
],
"Musician" => [
Models::Musician.new("Herbie Hancock", Models::Key.from_notation("B♭")),
],
}
end
def self.data
@data || reset
end
end
class BaseArgument < GraphQL::Schema::Argument
def initialize(*args, custom: nil, **kwargs)
@custom = custom
super(*args, **kwargs)
end
end
# A custom field class that supports the `upcase:` option
class BaseField < GraphQL::Schema::Field
argument_class BaseArgument
attr_reader :upcase
def initialize(*args, **options, &block)
@upcase = options.delete(:upcase)
super(*args, **options, &block)
end
def resolve_field(*)
result = super
if @upcase && result
result.upcase
else
result
end
end
def resolve(*)
result = super
if @upcase && result
result.upcase
else
result
end
end
end
class BaseObject < GraphQL::Schema::Object
# Use this overridden field class
field_class BaseField
class << self
def config(key, value)
configs[key] = value
end
def configs
@configs ||= {}
end
end
end
module BaseInterface
include GraphQL::Schema::Interface
# Use this overridden field class
field_class BaseField
# These methods are available to child interfaces
definition_methods do
def upcased_field(*args, **kwargs, &block)
field(*args, upcase: true, **kwargs, &block)
end
end
end
class BaseEnumValue < GraphQL::Schema::EnumValue
def initialize(*args, custom_setting: nil, **kwargs, &block)
@custom_setting = custom_setting
super(*args, **kwargs, &block)
end
end
class BaseEnum < GraphQL::Schema::Enum
enum_value_class BaseEnumValue
end
# Some arbitrary global ID scheme
# *Type suffix is removed automatically
module GloballyIdentifiableType
include BaseInterface
description "A fetchable object in the system"
field(
name: :id,
type: ID,
null: false,
description: "A unique identifier for this object",
)
upcased_field :upcased_id, ID, null: false, resolver_method: :id # upcase: true added by helper
def id
GloballyIdentifiableType.to_id(@object)
end
def self.to_id(object)
"#{object.class.name.split("::").last}/#{object.name}"
end
def self.find(id)
class_name, object_name = id.split("/")
Models.data[class_name].find { |obj| obj.name == object_name }
end
end
module WithNameField
def self.prepended(base)
base.field :name, String, null: false
end
end
module NamedEntity
include BaseInterface
prepend WithNameField
end
class PrivateMembership < GraphQL::Schema::TypeMembership
def initialize(*args, visibility: nil, **kwargs)
@visibility = visibility
super(*args, **kwargs)
end
def visible?(ctx)
return true if @visibility.nil?
@visibility[:private] && ctx[:private]
end
end
module PrivateNameEntity
include BaseInterface
type_membership_class PrivateMembership
field :private_name, String, null: false
def private_name
"private name"
end
end
module InvisibleNameEntity
include BaseInterface
field :invisible_name, String, null: false
field :overridden_name, String, null: false
def self.visible?(ctx)
ctx[:private]
end
end
# test field inheritance
class ObjectWithUpcasedName < BaseObject
# Test extra arguments:
field :upcase_name, String, null: false, upcase: true
def upcase_name
object.name # upcase is applied by the superclass
end
end
module HasMusicians
include BaseInterface
field :musicians, "[Jazz::Musician]", null: false
end
# Here's a new-style GraphQL type definition
class Ensemble < ObjectWithUpcasedName
# Test string type names
# This method should override inherited one
field :name, "String", null: false, resolver_method: :overridden_name
implements GloballyIdentifiableType, NamedEntity, HasMusicians, InvisibleNameEntity
implements PrivateNameEntity, visibility: { private: true }
description "A group of musicians playing together"
config :config, :configged
field :formed_at, String, hash_key: "formedAtDate"
# This overrides the visibility from PrivateNameEntity
field :overridden_name, String, null: false
def overridden_name
@object.name.sub("Robert Glasper", "ROBERT GLASPER")
end
def self.authorized?(object, context)
# Spinal Tap is top-secret, don't show it to anyone.
obj_name = object.is_a?(Hash) ? object[:name] : object.name
obj_name != "Spinal Tap"
end
end
class Family < BaseEnum
description "Groups of musical instruments"
# support string and symbol
value "STRING", "Makes a sound by vibrating strings", value: :str, custom_setting: 1
value :WOODWIND, "Makes a sound by vibrating air in a pipe"
value :BRASS, "Makes a sound by amplifying the sound of buzzing lips"
value "PERCUSSION", "Makes a sound by hitting something that vibrates",
value_method: :precussion_custom_value_method
value "DIDGERIDOO", "Makes a sound by amplifying the sound of buzzing lips", deprecation_reason: "Merged into BRASS"
value "KEYS" do
description "Neither here nor there, really"
end
value "SILENCE", "Makes no sound", value: false
end
class InstrumentType < BaseObject
implements NamedEntity
implements GloballyIdentifiableType
field :upcased_id, ID, null: false
def upcased_id
GloballyIdentifiableType.to_id(object).upcase
end
field :family, Family, null: false
end
class Key < GraphQL::Schema::Scalar
description "A musical key"
def self.coerce_input(val, ctx)
Models::Key.from_notation(val)
end
def self.coerce_result(val, ctx)
val.to_notation
end
end
class Musician < BaseObject
implements GloballyIdentifiableType
implements NamedEntity
description "Someone who plays an instrument"
field :instrument, InstrumentType, null: false do
description "An object played in order to produce music"
end
field :favorite_key, Key
# Test lists with nullable members:
field :inspect_context, [String, null: true], null: false
field :add_error, String, null: false, extras: [:execution_errors]
def inspect_context
[
@context.custom_method,
@context[:magic_key],
@context[:normal_key],
nil,
]
end
def add_error(execution_errors:)
execution_errors.add("this has a path")
"done"
end
end
class StylishMusician < Musician
field :sunglasses_type, String, null: false
def sunglasses_type
"cool 😎"
end
end
# Since this is not a legacy input type, this test can be removed
class LegacyInputType < GraphQL::Schema::InputObject
argument :int_value, Int
end
class FullyOptionalInput < GraphQL::Schema::InputObject
argument :optional_value, String, required: false
end
class InspectableInput < GraphQL::Schema::InputObject
argument :ensemble_id, ID, required: false, loads: Ensemble
argument :string_value, String, description: "Test description kwarg"
argument :nested_input, InspectableInput, required: false
argument :legacy_input, LegacyInputType, required: false
def helper_method
[
# Context is available in the InputObject
context[:message],
# ~~A GraphQL::Query::Arguments instance is available~~ not anymore
self[:string_value],
# Legacy inputs have underscored method access too
legacy_input ? legacy_input.int_value : "-",
# Access by method call is available
"(#{nested_input ? nested_input.helper_method : "-"})",
].join(", ")
end
end
class InspectableKey < BaseObject
field :root, String, null: false
field :is_sharp, Boolean, null: false, method: :sharp
field :is_flat, Boolean, null: false, method: :flat
end
class PerformingActVisibility < GraphQL::Schema::TypeMembership
def initialize(*args, visibility: nil, **kwargs)
@visibility = visibility
super(*args, **kwargs)
end
def visible?(ctx)
return true if @visibility.nil?
!ctx[@visibility]
end
end
class PerformingAct < GraphQL::Schema::Union
type_membership_class PerformingActVisibility
possible_types Musician
possible_types Ensemble, visibility: :hide_ensemble
def self.resolve_type(object, context)
GraphQL::Execution::Lazy.new do
if object.is_a?(Models::Ensemble)
Ensemble
else
Musician
end
end
end
end
class HashKeyTest < BaseObject
field :falsey, Boolean, null: false
end
class CamelizedBooleanInput < GraphQL::Schema::InputObject
argument :camelized_boolean, Boolean
end
# Another new-style definition, with method overrides
class Query < BaseObject
field :ensembles, [Ensemble], null: false
field :find, GloballyIdentifiableType do
argument :id, ID
end
field :instruments, [InstrumentType], null: false do
argument :family, Family, required: false
end
field :inspect_input, [String], null: false do
argument :input, InspectableInput, custom: :ok
end
field :inspect_key, InspectableKey, null: false do
argument :key, Key
end
field :now_playing, PerformingAct, null: false
def now_playing; Models.data["Ensemble"].first; end
# For asserting that the *resolver* object is initialized once:
# `method_conflict_warning: false` tells graphql-ruby that exposing Object#object_id was intentional
field :object_id, String, null: false, method_conflict_warning: false
field :inspect_context, [String], null: false
field :hashy_ensemble, Ensemble, null: false
field :echo_json, GraphQL::Types::JSON, null: false do
argument :input, GraphQL::Types::JSON
end
field :echo_first_json, GraphQL::Types::JSON, null: false do
argument :input, [GraphQL::Types::JSON]
end
field :upcase_check_1, String, resolver_method: :upcase_check, extras: [:upcase]
field :upcase_check_2, String, null: false, upcase: false, resolver_method: :upcase_check, extras: [:upcase]
field :upcase_check_3, String, null: false, upcase: true, resolver_method: :upcase_check, extras: [:upcase]
field :upcase_check_4, String, null: false, upcase: "why not?", resolver_method: :upcase_check, extras: [:upcase]
def upcase_check(upcase:)
upcase.inspect
end
field :input_object_camelization, String, null: false do
argument :input, CamelizedBooleanInput
end
def input_object_camelization(input:)
input.to_h.inspect
end
def ensembles
# Filter out the unauthorized one to avoid an error later
Models.data["Ensemble"].select { |e| e.name != "Spinal Tap" }
end
def find(id:)
if id == "MagicalSkipId"
context.skip
else
GloballyIdentifiableType.find(id)
end
end
def instruments(family: nil)
objs = Models.data["Instrument"]
if family
objs = objs.select { |i| i.family == family }
end
objs
end
# This is for testing input object behavior
def inspect_input(input:)
[
input.class.name,
input.helper_method,
# Access by method
input.string_value,
# Access by key:
input[:string_value],
input.key?(:string_value).to_s,
# ~~Access by legacy key~~ # not anymore
input[:string_value],
input.ensemble || "No ensemble",
input.key?(:ensemble).to_s,
]
end
def inspect_key(key:)
key
end
def inspect_context
[
context.custom_method,
context[:magic_key],
context[:normal_key],
]
end
def hashy_ensemble
# Both string and symbol keys are supported:
{
name: "The Grateful Dead",
"musicians" => [
OpenStruct.new(name: "Jerry Garcia"),
],
"formedAtDate" => "May 5, 1965",
}
end
def echo_json(input:)
input
end
def echo_first_json(input:)
input.first
end
field :hash_by_string, HashKeyTest, null: false
field :hash_by_sym, HashKeyTest, null: false
def hash_by_string
{"falsey" => false}
end
def hash_by_sym
{falsey: false}
end
field :named_entities, [NamedEntity, null: true], null: false
def named_entities
[Models.data["Ensemble"].first, nil]
end
field :default_value_test, String, null: false do
argument :arg_with_default, InspectableInput, required: false, default_value: { string_value: "S" }
end
def default_value_test(arg_with_default:)
"#{arg_with_default.class.name} -> #{arg_with_default.to_h}"
end
field :default_value_test_2, String, null: false, resolver_method: :default_value_test do
argument :arg_with_default, FullyOptionalInput, required: false, default_value: {}
end
field :complex_hash_key, String, null: false, hash_key: :'foo bar/fizz-buzz'
field :nullable_ensemble, Ensemble do
argument :ensemble_id, ID, required: false, loads: Ensemble
end
def nullable_ensemble(ensemble: nil)
ensemble
end
end
class EnsembleInput < GraphQL::Schema::InputObject
argument :name, String
end
class AddInstrument < GraphQL::Schema::Mutation
class << self
def prepare_name(value, context)
value.capitalize
end
end
null true
description "Register a new musical instrument in the database"
argument :name, String, prepare: :prepare_name
argument :family, Family
field :instrument, InstrumentType, null: false
# This is meaningless, but it's to test the conflict with `Hash#entries`
field :entries, [InstrumentType], null: false
# Test `extras` injection
field :ee, String, null: false
extras [:execution_errors]
def resolve(name:, family:, execution_errors:)
instrument = Jazz::Models::Instrument.new(name, family)
Jazz::Models.data["Instrument"] << instrument
{instrument: instrument, entries: Jazz::Models.data["Instrument"], ee: execution_errors.class.name}
end
end
class AddEnsembleRelay < GraphQL::Schema::RelayClassicMutation
argument :ensemble, EnsembleInput
field :ensemble, Ensemble, null: false
def resolve(ensemble:)
ens = Models::Ensemble.new(ensemble.name)
Models.data["Ensemble"] << ens
{ ensemble: ens }
end
end
class AddSitar < GraphQL::Schema::RelayClassicMutation
null true
description "Get Sitar to musical instrument"
field :instrument, InstrumentType, null: false
def resolve
instrument = Models::Instrument.new("Sitar", :str)
{instrument: instrument}
end
end
class HasExtras < GraphQL::Schema::RelayClassicMutation
null true
description "Test extras in RelayClassicMutation"
argument :int, Integer, required: false
extras [:ast_node]
field :node_class, String, null: false
field :int, Integer
def resolve(int: nil, ast_node:)
{
int: int,
node_class: ast_node.class.name,
}
end
end
class HasFieldExtras < GraphQL::Schema::RelayClassicMutation
null true
description "Test field with extras in RelayClassicMutation"
argument :int, Integer, required: false
field :lookahead_class, String, null: false
field :int, Integer
def resolve(int: nil, lookahead:)
{
int: int,
lookahead_class: lookahead.class.name,
}
end
end
class StripsExtras < GraphQL::Schema::RelayClassicMutation
extras [:lookahead]
def resolve_with_support(lookahead: , **rest)
context[:has_lookahead] = !!lookahead
super(**rest)
end
end
class HasExtrasStripped < StripsExtras
field :int, Integer, null: false
def authorized?
true
end
def resolve
{
int: 51,
}
end
end
class RenameNamedEntity < GraphQL::Schema::RelayClassicMutation
argument :named_entity_id, ID, loads: NamedEntity
argument :new_name, String
field :named_entity, NamedEntity, null: false
def resolve(named_entity:, new_name:)
# doesn't actually update the "database"
dup_named_entity = named_entity.dup
dup_named_entity.name = new_name
{
named_entity: dup_named_entity
}
end
end
class RenamePerformingAct < GraphQL::Schema::RelayClassicMutation
argument :performing_act_id, ID, loads: PerformingAct
argument :new_name, String
field :performing_act, PerformingAct, null: false
def resolve(performing_act:, new_name:)
# doesn't actually update the "database"
dup_performing_act = performing_act.dup
dup_performing_act.name = new_name
{
performing_act: dup_performing_act
}
end
end
class RenameEnsemble < GraphQL::Schema::RelayClassicMutation
argument :ensemble_id, ID, loads: Ensemble
argument :new_name, String
field :ensemble, Ensemble, null: false
def resolve(ensemble:, new_name:)
# doesn't actually update the "database"
dup_ensemble = ensemble.dup
dup_ensemble.name = new_name
{
ensemble: dup_ensemble,
}
end
end
class UpvoteEnsembles < GraphQL::Schema::RelayClassicMutation
argument :ensemble_ids, [ID], loads: Ensemble
field :ensembles, [Ensemble], null: false
def resolve(ensembles:)
{
ensembles: ensembles
}
end
end
class UpvoteEnsemblesAsBands < GraphQL::Schema::RelayClassicMutation
argument :ensemble_ids, [ID], loads: Ensemble, as: :bands
field :ensembles, [Ensemble], null: false
def resolve(bands:)
{
ensembles: bands
}
end
end
class UpvoteEnsemblesIds < GraphQL::Schema::RelayClassicMutation
argument :ensembles_ids, [ID], loads: Ensemble
field :ensembles, [Ensemble], null: false
def resolve(ensembles:)
{
ensembles: ensembles
}
end
end
class RenameEnsembleAsBand < RenameEnsemble
argument :ensemble_id, ID, loads: Ensemble, as: :band
# This is duplicate to the inherited one; make sure it overrides it
field :ensemble, Ensemble, null: false
def resolve(band:, new_name:)
super(ensemble: band, new_name: new_name)
end
end
class LoadAndReturnEnsemble < GraphQL::Schema::RelayClassicMutation
argument :ensemble_id, ID, required: false, loads: Ensemble
field :ensemble, Ensemble
def resolve(ensemble: nil)
{ ensemble: ensemble }
end
end
class DummyOutput < GraphQL::Schema::Object
graphql_name "DummyOutput"
field :name, String
end
class ReturnsMultipleErrors < GraphQL::Schema::Mutation
field :dummy_field, DummyOutput, null: false
def resolve
[
GraphQL::ExecutionError.new("First error"),
GraphQL::ExecutionError.new("Second error")
]
end
end
class ReturnInvalidNull < GraphQL::Schema::Mutation
field :int, Integer, null: false
def resolve
{ int: nil }
end
end
class Mutation < BaseObject
field :add_ensemble, Ensemble, null: false do
argument :input, EnsembleInput
end
field :add_instrument, mutation: AddInstrument
field :add_ensemble_relay, mutation: AddEnsembleRelay
field :add_sitar, mutation: AddSitar
field :rename_ensemble, mutation: RenameEnsemble
field :rename_named_entity, mutation: RenameNamedEntity
field :rename_performing_act, mutation: RenamePerformingAct
field :upvote_ensembles, mutation: UpvoteEnsembles
field :upvote_ensembles_as_bands, mutation: UpvoteEnsemblesAsBands
field :upvote_ensembles_ids, mutation: UpvoteEnsemblesIds
field :rename_ensemble_as_band, mutation: RenameEnsembleAsBand
field :load_and_return_ensemble, mutation: LoadAndReturnEnsemble
field :returns_multiple_errors, mutation: ReturnsMultipleErrors, null: false
field :has_extras, mutation: HasExtras
field :has_extras_stripped, mutation: HasExtrasStripped
field :has_field_extras, mutation: HasFieldExtras, extras: [:lookahead]
field :return_invalid_null, mutation: ReturnInvalidNull
def add_ensemble(input:)
ens = Models::Ensemble.new(input.name)
Models.data["Ensemble"] << ens
ens
end
field :prepare_input, Integer, null: false do
argument :input, Integer, prepare: :square, as: :squared_input
end
def prepare_input(squared_input:)
# Test that `square` is called
squared_input
end
def square(value)
value ** 2
end
end
class CustomContext < GraphQL::Query::Context
def [](key)
if key == :magic_key
"magic_value"
else
super
end
end
def custom_method
"custom_method"
end
end
module Introspection
class TypeType < GraphQL::Introspection::TypeType
def self.authorized?(_obj, ctx)
if ctx[:cant_introspect]
raise GraphQL::ExecutionError, "You're not allowed to introspect here"
else
super
end
end
def name
n = object.graphql_name
n && n.upcase
end
end
class NestedType < GraphQL::Introspection::TypeType
def name
object.name.upcase
end
class DeeplyNestedType < GraphQL::Introspection::TypeType
def name
object.name.upcase
end
end
end
class SchemaType < GraphQL::Introspection::SchemaType
graphql_name "__Schema"
field :is_jazzy, Boolean, null: false
def is_jazzy
true
end
end
class DynamicFields < GraphQL::Introspection::DynamicFields
field :__typename_length, Int, null: false
field :__ast_node_class, String, null: false, extras: [:ast_node]
def __typename_length
__typename.length
end
def __ast_node_class(ast_node:)
ast_node.class.name
end
end
class EntryPoints < GraphQL::Introspection::EntryPoints
field :__classname, String, "The Ruby class name of the root object", null: false
def __classname
object.object.class.name
end
end
end
# New-style Schema definition
class Schema < GraphQL::Schema
query(Query)
mutation(Mutation)
context_class CustomContext
introspection(Introspection)
def self.resolve_type(type, obj, ctx)
class_name = obj.class.name.split("::").last
ctx.schema.types[class_name] || raise("No type for #{obj.inspect}")
end
def self.object_from_id(id, ctx)
GloballyIdentifiableType.find(id)
end
BlogPost = Class.new(GraphQL::Schema::Object)
BlogPost.has_no_fields(true)
extra_types BlogPost
use GraphQL::Dataloader
use GraphQL::Schema::Warden if ADD_WARDEN
end
class SchemaWithoutIntrospection < GraphQL::Schema
query(Query)
disable_introspection_entry_points
use GraphQL::Dataloader
use GraphQL::Schema::Warden if ADD_WARDEN
end
class SchemaWithoutSchemaIntrospection < GraphQL::Schema
query(Query)
disable_schema_introspection_entry_point
use GraphQL::Schema::Warden if ADD_WARDEN
end
class SchemaWithoutTypeIntrospection < GraphQL::Schema
query(Query)
disable_type_introspection_entry_point
use GraphQL::Schema::Warden if ADD_WARDEN
end
class SchemaWithoutSchemaOrTypeIntrospection < GraphQL::Schema
query(Query)
disable_schema_introspection_entry_point
disable_type_introspection_entry_point
use GraphQL::Schema::Warden if ADD_WARDEN
end
end
|