public static DeepEquals ( object>.IDictionary |
||
results | object>.IDictionary | |
json | string | |
리턴 | void |
public static void TypenameR2Droid <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("query CheckTypeOfR2 { hero { __typename, name } }"); Test.DeepEquals(results, "{ hero: { __typename: 'Droid', name: 'R2-D2' } }"); }
public static void TypenameLukeHuman <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("query CheckTypeOfLuke { hero(episode: EMPIRE) { __typename, name } }"); Test.DeepEquals(results, "{ hero: { __typename: 'Human', name: 'Luke Skywalker' } }"); }
public static void BasicQueryHeroWithIdAndFriends <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("query HeroNameQuery { hero { id, name, friends { name } } }"); Test.DeepEquals(results, "{ hero: { id: '2001', name: 'R2-D2', friends: [ { name: 'Luke Skywalker' },{ name: 'Han Solo' }, { name: 'Leia Organa'} ] } }"); }
public static void FragmentsDuplicatedContent <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( @" query DuplicateFields { luke: human(id: ""1000"") { name homePlanet } leia: human(id: ""1003"") { name homePlanet } } " ); Test.DeepEquals(results, @" { luke: { name: 'Luke Skywalker', homePlanet: 'Tatooine' }, leia: { name: 'Leia Organa', homePlanet: 'Alderaan' } } "); }
public static void ByteArrayParameter <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ account(id:1) { id, byteArray } }"); Test.DeepEquals(results, "{ account: { id: 1, byteArray: 'AQIDBA==' } }"); // [1, 2, 3, 4] serialized to base64 by Json.NET }
public void EnumTypeDirectFields() { var gql = MemContext.CreateDefaultContext(); var results = gql.ExecuteQuery("{ __type(name: \"AccountType\") { name, description, kind } }"); Test.DeepEquals(results, "{ __type: { name: 'AccountType', description: null, kind: 'ENUM' } }"); }
public static void BasicQueryFetchLuke <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("query FetchLukeQuery { human(id: \"1000\") { name } }"); Test.DeepEquals(results, "{ human: { name: 'Luke Skywalker' } }"); }
public void TypeDirectFields() { var gql = MemContext.CreateDefaultContext(); var results = gql.ExecuteQuery("{ __type(name: \"User\") { name, description, kind } }"); Test.DeepEquals(results, "{ __type: { name: 'User', description: '', kind: 'OBJECT' } }"); }
public static void ChildFieldWithParameters <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ account(id:1) { id, name, firstUserWithActive(active:true) { id, name } } }"); Test.DeepEquals(results, "{ account: { id: 1, name: 'My Test Account', firstUserWithActive: { id: 1, name: 'Joe User' } } }"); results = gql.ExecuteQuery("{ account(id:1) { id, name, firstUserWithActive(active:false) { id, name } } }"); Test.DeepEquals(results, "{ account: { id: 1, name: 'My Test Account', firstUserWithActive: null } }"); }
public static void EnumerableSubField <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ account(id:1) { activeUsers { id, name } } }"); Test.DeepEquals(results, "{ account: { activeUsers: [{ id: 1, name: 'Joe User' }] } }"); var results2 = gql.ExecuteQuery("{ account(id:2) { activeUsers { id, name } } }"); Test.DeepEquals(results2, "{ account: { activeUsers: [] } }"); }
public static void SimpleMutation <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("mutation { mutate(id:1,newVal:5) { id, value } }"); Test.DeepEquals(results, "{ mutate: { id: 1, value: 5 } }"); var results2 = gql.ExecuteQuery("mutation { mutate(id:1,newVal:123) { id, value } }"); Test.DeepEquals(results2, "{ mutate: { id: 1, value: 123 } }"); }
public static void EnumFieldQuery <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ accountsByType(accountType:accountType_Gold) { id, accountType } }"); Test.DeepEquals(results, @"{ accountsByType: [ { id: 1, accountType: 'Gold' } ] }"); }
public static void GuidParameter <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ accountsByGuid(guid:\"00000000-0000-0000-0000-000000000000\") { id, someGuid } }"); Test.DeepEquals(results, @"{ accountsByGuid: [ { id: 1, someGuid: '00000000-0000-0000-0000-000000000000' }, { id: 2, someGuid: '00000000-0000-0000-0000-000000000000' }, ] }"); }
public static void UnionTypeDroid <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( @"query UnionTypeStarshipQuery { search(text: ""droid"") { __typename } }"); Test.DeepEquals(results, "{ search: { __typename: 'Droid'} }"); }
public static void InlineFragementWithoutTypenameField <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ heros { name, ... on Stormtrooper { height, specialization } } }"); Test.DeepEquals( results, "{ heros: [ " + "{ name: 'Han Solo'}, " + "{ name: 'FN-2187', height: 4.9, specialization: 'Imperial Snowtrooper'}, " + "{ name: 'R2-D2' } ] }" ); }
public static void InlineFragementWithoutTypenameFieldWithoutOtherFields <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ heros { ... on Stormtrooper { height, specialization } } }"); Test.DeepEquals( results, "{ heros: [ " + "{ }, " + "{ height: 4.9, specialization: 'Imperial Snowtrooper'}, " + "{ } ] }" ); }
public static void IntrospectionDroidType <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( @"query IntrospectionDroidTypeQuery { __type(name: ""Droid"") { name } }"); Test.DeepEquals(results, "{ __type: { name: 'Droid' } }"); }
public static void FragementWithMultiLevelInheritance <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ heros { name, __typename, ... on Stormtrooper { height, specialization } } }"); Test.DeepEquals( results, "{ heros: [ " + "{ name: 'Han Solo', __typename: 'Human'}, " + "{ name: 'FN-2187', __typename: 'Stormtrooper', height: 4.9, specialization: 'Imperial Snowtrooper'}, " + "{ name: 'R2-D2', __typename: 'Droid' } ] }" ); }
public static void FragementWithMultipleTypenameFieldsMixedWithInlineFragment <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( "{ heros { ...stormtrooper, __typename, ... on Human {name}, ... on Droid {name}}}, fragment stormtrooper on Stormtrooper { name, height, specialization, __typename } "); Test.DeepEquals( results, "{ heros: [ " + "{ __typename: 'Human', name: 'Han Solo'}, " + "{ name: 'FN-2187', height: 4.9, specialization: 'Imperial Snowtrooper', __typename: 'Stormtrooper'}, " + "{ __typename: 'Droid', name: 'R2-D2'} ] }" ); }
public static void IntrospectionCharacterInterface <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( @"query IntrospectionCharacterKindQuery { __type(name: ""ICharacter"") { name kind } }"); Test.DeepEquals(results, "{ __type: { name: 'ICharacter', kind: 'INTERFACE' } }"); }
public static void InlineFragementWithListField <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( "{ heros { name, __typename, ... on Human { height, vehicles { name } }, ... on Stormtrooper { specialization }, " + "... on Droid { primaryFunction } } }"); Test.DeepEquals( results, "{ heros: [ " + "{ name: 'Han Solo', __typename: 'Human', height: 5.6430448, vehicles: [ {name: 'Millennium falcon'}] }, " + "{ name: 'FN-2187', __typename: 'Stormtrooper', height: 4.9, vehicles: [ {name: 'Speeder bike'}], specialization: 'Imperial Snowtrooper'}, " + "{ name: 'R2-D2', __typename: 'Droid', primaryFunction: 'Astromech' } ] }" ); }
public void AddAllFields() { var schema = GraphQL <MemContext> .CreateDefaultSchema(() => new MemContext()); schema.AddType <User>().AddAllFields(); schema.AddType <Account>().AddAllFields(); schema.AddField("user", new { id = 0 }, (db, args) => db.Users.AsQueryable().FirstOrDefault(u => u.Id == args.id)); schema.Complete(); var gql = new GraphQL <MemContext>(schema); var results = gql.ExecuteQuery("{ user(id:1) { id, name } }"); Test.DeepEquals(results, "{ user: { id: 1, name: 'Joe User' } }"); }
public static void InlineFragements <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( "{ heros { name, __typename, ... on Human { height }, ... on Stormtrooper { specialization }, " + "... on Droid { primaryFunction } } }"); Test.DeepEquals( results, "{ heros: [ " + "{ name: 'Han Solo', __typename: 'Human', height: 5.6430448}, " + "{ name: 'FN-2187', __typename: 'Stormtrooper', height: 4.9, specialization: 'Imperial Snowtrooper'}, " + "{ name: 'R2-D2', __typename: 'Droid', primaryFunction: 'Astromech' } ] }" ); }
public void ChildFieldType() { var gql = MemContext.CreateDefaultContext(); var results = gql.ExecuteQuery("{ __type(name: \"User\") { fields { name, type { name, kind, ofType { name, kind } } } } }"); Test.DeepEquals(results, @"{ __type: { fields: [ { name: 'id', type: { name: null, kind: 'NON_NULL', ofType: { name: 'Int', kind: 'SCALAR' } } }, { name: 'name', type: { name: 'String', kind: 'SCALAR', ofType: null } }, { name: 'account', type: { name: 'Account', kind: 'OBJECT', ofType: null } }, { name: 'nullRef', type: { name: 'NullRef', kind: 'OBJECT', ofType: null } }, { name: 'total', type: { name: null, kind: 'NON_NULL', ofType: { name: 'Int', kind: 'SCALAR' } } }, { name: 'accountPaid', type: { name: null, kind: 'NON_NULL', ofType: { name: 'Boolean', kind: 'SCALAR' } } }, { name: 'abc', type: { name: 'String', kind: 'SCALAR', ofType: null } }, { name: 'sub', type: { name: 'Sub', kind: 'OBJECT', ofType: null } }, { name: '__typename', type: { name: 'String', kind: 'SCALAR', ofType: null } } ] } }"); }
public void TypeWithChildFields() { var gql = MemContext.CreateDefaultContext(); var results = gql.ExecuteQuery("{ __type(name: \"User\") { fields { name } } }"); Test.DeepEquals(results, @"{ __type: { fields: [ { name: 'id' }, { name: 'name' }, { name: 'account' }, { name: 'nullRef' }, { name: 'total' }, { name: 'accountPaid' }, { name: 'abc' }, { name: 'sub' }, { name: '__typename' } ] } }"); }
public static void FragmentsInlineFragments <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery( @"query UseInlineFragments { luke: hero(episode: EMPIRE) { ...HumanFragment, ...DroidFragment } r2d2: hero { ...HumanFragment, ...DroidFragment } } fragment HumanFragment on Human { name homePlanet } fragment DroidFragment on Droid { name primaryFunction } " ); Test.DeepEquals(results, @" { luke: { name: 'Luke Skywalker', homePlanet: 'Tatooine' }, r2d2: { name: 'R2-D2', primaryFunction: 'Astromech' } } "); }
public static void DateTimeFilter <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ accountPaidBy(paid: { year: 2016 month: 1 day: 1 }) { id } }"); Test.DeepEquals(results, "{ accountPaidBy: { id: 1 } }"); }
public static void TypeName <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ user(id:1) { id, __typename } }"); Test.DeepEquals(results, "{ user: { id: 1, __typename: 'User' } }"); }
public static void PostFieldSubQuery <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ user(id:1) { sub { id } } }"); Test.DeepEquals(results, "{ user: { sub: { id: 1 } } }"); }
public static void PostField <TContext>(GraphQL <TContext> gql) { var results = gql.ExecuteQuery("{ user(id:1) { id, abc } }"); Test.DeepEquals(results, "{ user: { id: 1, abc: 'easy as 123' } }"); }