public ObjectFieldContext(FieldDefinition field, GraphQLGenerationOptions options, Document document, string propertyName) { this.field = field; this.options = options; this.document = document; this.Name = propertyName; }
public EnumValueContext(EnumValueDefinition entry, GraphQLGenerationOptions options, Document document, string propertyName) { this.Name = propertyName; this.entry = entry; this.options = options; this.document = document; }
public InputValueContext(InputValueDefinition arg, GraphQLGenerationOptions options, Document document, string propertyName) { this.arg = arg; this.options = options; this.document = document; this.PropertyName = propertyName; }
public DocumentContext(Document document, string filename, GraphQLGenerationOptions options) { this.document = document; UsingStatements = options.UsingStatements.ToArray(); FileName = filename; this.options = options; }
public static string ResolveIntrospection(this GraphQLGenerationOptions options, ITypeNode typeNode) { return(typeNode switch { NonNullType { BaseType : var baseType } => $"global::GraphLinqQL.Introspection.NonNullTypeInformation<{options.ResolveIntrospection(baseType)}>",
public virtual string GetTypeName(ITypeNode typeNode, GraphQLGenerationOptions options, Document document, bool nullable = true) { var nullability = nullable && options.ShowNullabilityIndicators() ? "?" : ""; return(typeNode switch { NonNullType { BaseType : var baseType } => GetTypeName(baseType, options, document, nullable : false),
internal static CompileResult Compile(Document document, string filename, GraphQLGenerationOptions options) { using var writer = new StringWriter(); var context = new DocumentContext(document, filename, options); GenerateGraphQLSchemaCode.RenderDocument(context, writer); return(new CompileResult(context.CompilerErrors, writer.ToString())); }
public static string?ObsoleteReason(this Directive obsoleteDirective, GraphQLGenerationOptions options, Document document) { var reason = obsoleteDirective.Arguments.FirstOrDefault(a => a.Name == "reason")?.Value; if (reason != null) { return(options.Resolve(reason, new TypeName("String", new LocationRange()), document)); } return(null); }
public virtual string Resolve(IValueNode value, ITypeNode typeNode, GraphQLGenerationOptions options, Document document) { return(value switch { ArrayValue array when typeNode is ListType list => $"new {options.Resolve(list.ElementType, document)} [] {{ {string.Join(", ", array.Values.Select(v => Resolve(v, list.ElementType, options, document)))} }}", BooleanValue booleanValue => booleanValue.TokenValue == true ? "true" : "false", EnumValue enumValue when typeNode is TypeName typeName => RenderEnumValue(enumValue, typeName, document, options), FloatValue floatValue => floatValue.TokenValue, IntValue intValue => intValue.TokenValue, NullValue _ => "null", ObjectValue objectValue when typeNode is TypeName typeName => RenderObjectInstantiation(objectValue, typeName, options, document), StringValue stringValue => $@"@""{stringValue.Text.Replace("\"", "\"\"")}""", TripleQuotedStringValue stringValue => $@"@""{stringValue.Text.Replace("\"", "\"\"")}""", _ => throw new InvalidOperationException($"Cannot render a C# representation for the default value of type {value.Kind.ToString("g")} for type {options.Resolve(typeNode, document, nullable: false)}"), });
public static void CompileFile(string inputFile, string outputFile, Action <CompilerError> logError, GraphQLGenerationOptions options) { if (string.IsNullOrEmpty(inputFile)) { throw new ArgumentNullException(nameof(inputFile)); } if (logError == null) { throw new ArgumentNullException(nameof(logError)); } outputFile ??= inputFile + ".g.cs"; var subject = File.ReadAllText(inputFile); var result = CompileString(subject, fileName: MakePragmaPath(inputFile, outputFile), options: options); var hadFatal = false; foreach (var error in result.Errors) { hadFatal |= !error.IsWarning; logError(error); } if (!hadFatal) { Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); File.WriteAllText(outputFile, result.Code); } else if (File.Exists(outputFile)) { File.Delete(outputFile); } }
public static string ResolveJson(this GraphQLGenerationOptions options, IValueNode value, ITypeNode typeNode, Document document) { return(options.ValueResolver.ResolveJson(value, typeNode, options, document)); }
public EnumTypeContext(EnumTypeDefinition enumTypeDefinition, GraphQLGenerationOptions options, Document document) { this.enumTypeDefinition = enumTypeDefinition; this.options = options; this.document = document; }
public DirectiveContext(DirectiveDefinition directive, GraphQLGenerationOptions options, Document document) { this.directive = directive; this.options = options; this.document = document; }
public static string Resolve(this GraphQLGenerationOptions options, ITypeNode typeNode, Document document, bool nullable = true) { return(options.TypeResolver.Resolve(typeNode, options, document, nullable: nullable)); }
public UnionTypeContext(UnionTypeDefinition unionTypeDefinition, GraphQLGenerationOptions options) { this.unionTypeDefinition = unionTypeDefinition; this.options = options; }
public string Resolve(ITypeNode typeNode, GraphQLGenerationOptions options, Document document, bool nullable = true) { return(GetTypeName(typeNode, options, document, nullable)); }
public ObjectTypeContext(ObjectTypeDefinition declaration, GraphQLGenerationOptions options, Document document) { this.declaration = declaration; this.options = options; this.document = document; }
public static bool ShowNullabilityIndicators(this GraphQLGenerationOptions options) => options.LanguageVersion >= 8;
public static CompileResult CompileString(string subject, string fileName, GraphQLGenerationOptions options) { var document = new AbstractSyntaxTreeGenerator().ParseDocument(subject ?? string.Empty); return(SyntaxCompiler.Compile(document, fileName, options)); }
public InterfaceTypeContext(InterfaceTypeDefinition interfaceTypeDefinition, GraphQLGenerationOptions options, Document document) { this.declaration = interfaceTypeDefinition; this.options = options; this.document = document; }
public ScalarTypeContext(ScalarTypeDefinition definition, GraphQLGenerationOptions options) { this.definition = definition; this.options = options; }