public static bool IsPossibleType( GraphQLBaseType parent, GraphQLBaseType child, ISchemaRepository schemaRepository) { return(parent .Introspect(schemaRepository) .Value .Interfaces.Any(e => e.Value.Name == child.Name)); }
private bool DoTypesOverlap(GraphQLBaseType fragmentType, GraphQLBaseType parentType) { if (fragmentType == parentType) { return(true); } var parentImplementsFragmentType = fragmentType .Introspect(this.SchemaRepository).Value .Interfaces?.Any(e => e.Value.Name == parentType.Name) ?? false; var fragmentTypeImplementsParent = parentType .Introspect(this.SchemaRepository).Value .Interfaces?.Any(e => e.Value.Name == fragmentType.Name) ?? false; var fragmentTypeIsWithinPossibleTypes = parentType .Introspect(this.SchemaRepository).Value .PossibleTypes?.Any(e => e.Value.Name == fragmentType.Name) ?? false; return(parentImplementsFragmentType || fragmentTypeImplementsParent || fragmentTypeIsWithinPossibleTypes); }
private IEnumerable <string> GetSuggestedFieldNames(IGraphQLSchema schema, GraphQLBaseType type, string fieldName) { if (type is GraphQLObjectType || type is GraphQLInterfaceType) { var introspectedType = type.Introspect(schema.SchemaRepository); var possibleFieldNames = introspectedType.Value.Fields.Select(e => e.Value.Name.Value); return(StringUtils.SuggestionList(fieldName, possibleFieldNames)); } return(Enumerable.Empty <string>()); }
private IEnumerable <string> GetSuggestedTypeNames(IGraphQLSchema schema, GraphQLBaseType type, string fieldName) { var introspectedType = type.Introspect(schema.SchemaRepository); var suggestedObjectTypes = new List <string>(); var interfaceUsageCount = new Dictionary <string, int>(); if (introspectedType.Value.PossibleTypes == null) { return(suggestedObjectTypes); } foreach (var possibleType in introspectedType.Value.PossibleTypes) { if (possibleType.Value.Fields.Any(e => e.Value.Name == fieldName)) { suggestedObjectTypes.Add(possibleType.Value.Name); foreach (var possibleInterface in possibleType.Value.Interfaces) { if (possibleInterface.Value.Fields.Any(e => e.Value.Name == fieldName)) { if (!interfaceUsageCount.ContainsKey(possibleInterface.Value.Name)) { interfaceUsageCount.Add(possibleInterface.Value.Name, 1); } else { interfaceUsageCount[possibleInterface.Value.Name]++; } } } } } var suggestedInterfaceTypes = interfaceUsageCount.OrderByDescending(e => e.Value).Select(e => e.Key); return(suggestedInterfaceTypes.Concat(suggestedObjectTypes)); }