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
|
use strict;
use warnings;
use lib './lib';
use Benchmark;
use GraphQL::Schema;
use GraphQL::Type::Object;
use GraphQL::Type::Scalar qw($String $Int $Boolean);
use GraphQL::Execution qw(execute);
use GraphQL::Language::Parser qw(parse);
###########
# Prep schema
my ($deep_data, $data);
$data = {
a => sub {'Apple'},
b => sub {'Banana'},
c => sub {'Cookie'},
d => sub {'Donut'},
e => sub {'Egg'},
f => 'Fish',
pic => sub {
my $size = shift;
return 'Pic of size: ' . ($size || 50);
},
deep => sub {$deep_data},
promise => sub { FakePromise->resolve($data) },
};
$deep_data = {
a => sub {'Already Been Done'},
b => sub {'Boring'},
c => sub { [ 'Contrived', undef, 'Confusing' ] },
deeper => sub { [ $data, undef, $data ] }
};
my ($DeepDataType, $DataType);
$DataType = GraphQL::Type::Object->new(
name => 'DataType',
fields => sub {
{
a => {type => $String},
b => {type => $String},
c => {type => $String},
d => {type => $String},
e => {type => $String},
f => {type => $String},
pic => {
args => {size => {type => $Int}},
type => $String,
resolve => sub {
my ($obj, $args) = @_;
return $obj->{pic}->($args->{size});
}
},
deep => {type => $DeepDataType},
promise => {type => $DataType},
}
}
);
$DeepDataType = GraphQL::Type::Object->new(
name => 'DeepDataType',
fields => {
a => {type => $String},
b => {type => $String},
c => {type => $String->list},
deeper => {type => $DataType->list},
}
);
my $schema = GraphQL::Schema->new(query => $DataType);
my $doc = <<'EOF';
query Example($size: Int) {
a,
b,
x: c
...c
f
...on DataType {
pic(size: $size)
promise {
a
}
}
deep {
a
b
c
deeper {
a
b
}
}
}
fragment c on DataType {
d
e
}
EOF
my $ast = parse($doc);
timethis(-5, sub { execute($schema, $ast, $data, undef, {size => 100}, 'Example') });
|