예제 #1
0
 public ObjectFieldContext(FieldDefinition field, GraphQLGenerationOptions options, Document document, string propertyName)
 {
     this.field    = field;
     this.options  = options;
     this.document = document;
     this.Name     = propertyName;
 }
예제 #2
0
 public EnumValueContext(EnumValueDefinition entry, GraphQLGenerationOptions options, Document document, string propertyName)
 {
     this.Name     = propertyName;
     this.entry    = entry;
     this.options  = options;
     this.document = document;
 }
예제 #3
0
 public InputValueContext(InputValueDefinition arg, GraphQLGenerationOptions options, Document document, string propertyName)
 {
     this.arg          = arg;
     this.options      = options;
     this.document     = document;
     this.PropertyName = propertyName;
 }
예제 #4
0
 public DocumentContext(Document document, string filename, GraphQLGenerationOptions options)
 {
     this.document   = document;
     UsingStatements = options.UsingStatements.ToArray();
     FileName        = filename;
     this.options    = options;
 }
예제 #5
0
 public static string ResolveIntrospection(this GraphQLGenerationOptions options, ITypeNode typeNode)
 {
     return(typeNode switch
     {
         NonNullType {
             BaseType : var baseType
         } => $"global::GraphLinqQL.Introspection.NonNullTypeInformation<{options.ResolveIntrospection(baseType)}>",
예제 #6
0
        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),
예제 #7
0
        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()));
        }
예제 #8
0
        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);
        }
예제 #9
0
 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)}"),
     });
예제 #10
0
        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);
            }
        }
예제 #11
0
 public static string ResolveJson(this GraphQLGenerationOptions options, IValueNode value, ITypeNode typeNode, Document document)
 {
     return(options.ValueResolver.ResolveJson(value, typeNode, options, document));
 }
예제 #12
0
 public EnumTypeContext(EnumTypeDefinition enumTypeDefinition, GraphQLGenerationOptions options, Document document)
 {
     this.enumTypeDefinition = enumTypeDefinition;
     this.options            = options;
     this.document           = document;
 }
예제 #13
0
 public DirectiveContext(DirectiveDefinition directive, GraphQLGenerationOptions options, Document document)
 {
     this.directive = directive;
     this.options   = options;
     this.document  = document;
 }
예제 #14
0
 public static string Resolve(this GraphQLGenerationOptions options, ITypeNode typeNode, Document document, bool nullable = true)
 {
     return(options.TypeResolver.Resolve(typeNode, options, document, nullable: nullable));
 }
예제 #15
0
 public UnionTypeContext(UnionTypeDefinition unionTypeDefinition, GraphQLGenerationOptions options)
 {
     this.unionTypeDefinition = unionTypeDefinition;
     this.options             = options;
 }
예제 #16
0
 public string Resolve(ITypeNode typeNode, GraphQLGenerationOptions options, Document document, bool nullable = true)
 {
     return(GetTypeName(typeNode, options, document, nullable));
 }
예제 #17
0
 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;
예제 #19
0
        public static CompileResult CompileString(string subject, string fileName, GraphQLGenerationOptions options)
        {
            var document = new AbstractSyntaxTreeGenerator().ParseDocument(subject ?? string.Empty);

            return(SyntaxCompiler.Compile(document, fileName, options));
        }
예제 #20
0
 public InterfaceTypeContext(InterfaceTypeDefinition interfaceTypeDefinition, GraphQLGenerationOptions options, Document document)
 {
     this.declaration = interfaceTypeDefinition;
     this.options     = options;
     this.document    = document;
 }
예제 #21
0
 public ScalarTypeContext(ScalarTypeDefinition definition, GraphQLGenerationOptions options)
 {
     this.definition = definition;
     this.options    = options;
 }