private string GenerateType(SetSelection selection, string operationName = null) { if (selection.SpecifiedTypeName is object) { if (specifiedNameToUniqueIdentifierLookup.TryGetValue(selection.SpecifiedTypeName.Value, out var key) && key != selection.UniqueIdentifier) { this.AddError($"'{selection.SpecifiedTypeName.Value}' already defined with different fields", selection.SpecifiedTypeName.Location); } } var lookupName = $"{operationName}_{selection.SpecifiedTypeName?.Value ?? selection.UniqueIdentifier}"; if (this.typeLookup.ContainsKey(lookupName)) { return(this.typeLookup[lookupName]?.Name); } string name = selection.SpecifiedTypeName?.Value ?? FindBestName((operationName ?? selection.RootType.Name), "Result"); TypeViewModel type = BuildTypeViewModel(selection, name, lookupName); if (selection.SpecifiedTypeName is object) { specifiedNameToUniqueIdentifierLookup[selection.SpecifiedTypeName.Value] = selection.UniqueIdentifier; } return(type.Name); }
private string GenerateType(IGraphQLType type) { if (this.inputTypeLookup.ContainsKey(type)) { return(this.inputTypeLookup[type]); } //lets make sure it exists string name = FindBestName(type.Name, ""); if (type is IGraphQLFieldCollection obj) { TypeViewModel typeVm = new TypeViewModel(name) { Fields = obj.Fields.Select(x => new NamedTypeViewModel() { Name = x.Name, Type = GenerateTypeReference(x.Type) }).ToList() }; this.inputTypeLookup.Add(type, typeVm.Name); this.typeCollection.Add(typeVm); return(typeVm.Name); } else if (type is EnumType enumObj) { EnumViewModel typeVm = new EnumViewModel(name) { Values = enumObj.Values }; this.inputTypeLookup.Add(type, typeVm.Name); this.enumCollection.Add(typeVm); return(typeVm.Name); } else if (type is FragmentType fragment) { TypeViewModel typeVm = BuildTypeViewModel(fragment.Selection, name, $"_{fragment.Selection}_[fragment]"); typeVm.IsInterface = true; fragmentQueries.Add(typeVm.Name, fragment.Query); this.inputTypeLookup.Add(type, typeVm.Name); return(typeVm.Name); } else { throw new Exception("unkown type"); // probably an enum type } }
private TypeViewModel BuildTypeViewModel(SetSelection selection, string name, string lookupName) { TypeViewModel type = new TypeViewModel(name); this.typeLookup.Add(lookupName, type); this.typeCollection.Add(type); type.Fields = selection.Fields.Select(x => new NamedTypeViewModel() { Name = x.Name, Type = GenerateTypeReference(x) }).ToList(); type.Interfaces = selection.Fragments.Select(x => GenerateType(x)).ToList(); return(type); }
private string GenerateType(IGraphQLType type) { if (inputTypeLookup.ContainsKey(type)) { return(inputTypeLookup[type]); } //lets make sure it exists var name = FindBestName(type.Name, ""); if (type is IGraphQLFieldCollection obj) { var typeVm = new TypeViewModel(name) { Fields = obj.Fields.Select(x => new NamedTypeViewModel() { Name = x.Name, Type = GenerateTypeReference(x.Type) }).ToList() }; inputTypeLookup.Add(type, typeVm.Name); typeCollection.Add(typeVm); return(typeVm.Name); } else if (type is EnumType enumObj) { var typeVm = new EnumViewModel(name) { Values = enumObj.Values }; inputTypeLookup.Add(type, typeVm.Name); enumCollection.Add(typeVm); return(typeVm.Name); } else { throw new Exception("unkown type"); // probably an enum type } }
private string GenerateType(SetSelection selection, string operationName = null) { if (typeLookup.ContainsKey($"{operationName}_{selection.UniqueIdentifier}")) { return(typeLookup[$"{operationName}_{selection.UniqueIdentifier}"]?.Name); } var name = FindBestName(operationName ?? selection.RootType.Name, "Result"); var type = new TypeViewModel(name) { Fields = selection.Fields.Select(x => new NamedTypeViewModel() { Name = x.Name, Type = GenerateTypeReference(x) }).ToList() }; typeLookup.Add($"{operationName}_{selection.UniqueIdentifier}", type); typeCollection.Add(type); return(type.Name); }