Skip to content

Commit

Permalink
Merge pull request #15 from graphql-dotnet/implemented-members-in-int…
Browse files Browse the repository at this point in the history
…erfaces

Implemented members in interfaces
  • Loading branch information
tlil authored Jan 30, 2017
2 parents 82705bb + 42644d2 commit 0225f27
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/GraphQL.Conventions/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
[assembly: AssemblyProduct("GraphQL.Conventions")]
[assembly: AssemblyCopyright("Copyright 2016-2017 Tommy Lillehagen. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.0.8.0")]
[assembly: AssemblyFileVersion("1.0.8.0")]
[assembly: AssemblyInformationalVersion("1.0.8.0")]
[assembly: AssemblyVersion("1.0.9.0")]
[assembly: AssemblyFileVersion("1.0.9.0")]
[assembly: AssemblyInformationalVersion("1.0.9.0")]
[assembly: CLSCompliant(false)]

[assembly: InternalsVisibleTo("GraphQL.Conventions.Tests")]
10 changes: 10 additions & 0 deletions src/GraphQL.Conventions/Types/Resolution/ObjectReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,23 @@ private TypeInfo GetTypeInfo(ICustomAttributeProvider attributeProvider) =>

private IEnumerable<GraphFieldInfo> GetFields(TypeInfo typeInfo)
{
var implementedProperties = typeInfo
.ImplementedInterfaces
.SelectMany(iface => iface.GetProperties(DefaultBindingFlags));

var properties = typeInfo
.GetProperties(DefaultBindingFlags)
.Union(implementedProperties)
.Where(IsValidMember)
.Where(propertyInfo => !propertyInfo.IsSpecialName);

var implementedMethods = typeInfo
.ImplementedInterfaces
.SelectMany(iface => iface.GetMethods(DefaultBindingFlags));

return typeInfo
.GetMethods(DefaultBindingFlags)
.Union(implementedMethods)
.Where(IsValidMember)
.Where(methodInfo => !methodInfo.IsSpecialName)
.Cast<MemberInfo>()
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL.Conventions/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.8-*",
"version": "1.0.9-*",
"description": "GraphQL Conventions for .NET",
"authors": [
"Tommy Lillehagen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public void Can_Construct_And_Describe_Schema_From_Abstract_Types()
var schema = engine.Describe();
schema.ShouldEqualWhenReformatted(@"
type Query {
commonField: Date!
someOtherField: String
commonField: Date!
someOtherField: String
}
");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Can_Construct_And_Describe_Schema_With_Injections()
var schema = engine.Describe();
schema.ShouldEqualWhenReformatted(@"
type Query {
field: String
field: String
}
");
}
Expand Down Expand Up @@ -47,11 +47,10 @@ public void Can_Construct_And_Describe_Schema_With_Injections_In_Generic_Methods
var schema = engine.Describe();
schema.ShouldEqualWhenReformatted(@"
schema {
query: QueryWithDIFields
query: QueryWithDIFields
}
type QueryWithDIFields {
withDependency: Int!
withDependency: Int!
}
");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using GraphQL.Conventions.Adapters.Engine;
using GraphQL.Conventions.Tests.Templates;
using GraphQL.Conventions.Tests.Templates.Extensions;
using GraphQL.Conventions.Types;
using Xunit;

namespace GraphQL.Conventions.Tests.Adapters.Engine
{
public class GenericTypesInInterfaceTests : TestBase
{
[Fact]
public void Can_Construct_And_Describe_Schema_Using_Interfaces_With_Generic_Types()
{
var engine = new GraphQLEngine();
engine.BuildSchema(typeof(SchemaDefinition<Query>));
var schema = engine.Describe();
schema.ShouldEqualWhenReformatted(@"
type Account implements IAccount {
id: Int!
}
interface IAccount {
id: Int!
}
type Query {
account: IAccount
}
");
}

[Fact]
public async void Can_Execute_Query_On_Schema_Using_Interfaces_With_Generic_Types()
{
var engine = new GraphQLEngine();
engine.BuildSchema(typeof(SchemaDefinition<Query>));
var result = await engine
.NewExecutor()
.WithQueryString("{ account { id } }")
.EnableValidation()
.Execute();

result.ShouldHaveNoErrors();
result.Data.ShouldHaveFieldWithValue("account", "id", 123);
}

interface IEntity<T>
{
T Id { get; }
}

interface IAccount : IEntity<int> { }

class Account : IAccount
{
public int Id { get; } = 123;
}

class Query
{
public IAccount Account { get; } = new Account();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ public void Can_Construct_And_Describe_Basic_Schema()
var schema = engine.Describe();
schema.ShouldEqualWhenReformatted(@"
schema {
query: BasicQuery
query: BasicQuery
}
type BasicQuery {
booleanField1: Boolean
booleanField2: Boolean!
dateField1: Date
dateField2: Date!
doubleField1: Float
doubleField2: Float!
floatField1: Float
floatField2: Float!
fooField1: Foo
fooField2: Foo!
intField1: Int
intField2: Int!
stringField1: String
stringField2: String!
timeSpanField1: TimeSpan
timeSpanField2: TimeSpan!
urlField1: URL
urlField2: URL!
booleanField1: Boolean
booleanField2: Boolean!
dateField1: Date
dateField2: Date!
doubleField1: Float
doubleField2: Float!
floatField1: Float
floatField2: Float!
fooField1: Foo
fooField2: Foo!
intField1: Int
intField2: Int!
stringField1: String
stringField2: String!
timeSpanField1: TimeSpan
timeSpanField2: TimeSpan!
urlField1: URL
urlField2: URL!
}
type Foo {
id: ID!
id: ID!
}
");
}
Expand All @@ -56,29 +56,29 @@ public void Can_Construct_And_Describe_Polymorphic_Schema()
var schema = engine.Describe();
schema.ShouldEqualWhenReformatted(@"
type Actor {
dateOfBirth: Date
firstName: String
lastName: String!
dateOfBirth: Date
firstName: String
lastName: String!
}
type ExtendedVersion implements ISemanticVersion {
branchName: String!
majorVersion: Int!
minorVersion: Int!
revision: Int!
branchName: String!
majorVersion: Int!
minorVersion: Int!
revision: Int!
}
interface ISemanticVersion {
majorVersion: Int!
minorVersion: Int!
revision: Int!
majorVersion: Int!
minorVersion: Int!
revision: Int!
}
type Movie {
actors: [Actor]
releaseDate: Date
title: String!
actors: [Actor]
releaseDate: Date
title: String!
}
type Query {
search(searchFor: String!): [SearchResult]
version(branchName: String): ISemanticVersion
search(searchFor: String!): [SearchResult]
version(branchName: String): ISemanticVersion
}
type SearchResult {
node: SearchResultItem
Expand Down

0 comments on commit 0225f27

Please sign in to comment.