Exemplo n.º 1
0
 public ObjectFieldContext(FieldDefinition field, GraphQLGenerationOptions options, Document document, string propertyName)
 {
     this.field    = field;
     this.options  = options;
     this.document = document;
     this.Name     = propertyName;
 }
Exemplo n.º 2
0
 public EnumValueContext(EnumValueDefinition entry, GraphQLGenerationOptions options, Document document, string propertyName)
 {
     this.Name     = propertyName;
     this.entry    = entry;
     this.options  = options;
     this.document = document;
 }
Exemplo n.º 3
0
 public InputValueContext(InputValueDefinition arg, GraphQLGenerationOptions options, Document document, string propertyName)
 {
     this.arg          = arg;
     this.options      = options;
     this.document     = document;
     this.PropertyName = propertyName;
 }
Exemplo n.º 4
0
 public DocumentContext(Document document, string filename, GraphQLGenerationOptions options)
 {
     this.document   = document;
     UsingStatements = options.UsingStatements.ToArray();
     FileName        = filename;
     this.options    = options;
 }
Exemplo n.º 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)}>",
Exemplo n.º 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),
Exemplo n.º 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()));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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)}"),
     });
Exemplo n.º 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);
            }
        }
Exemplo n.º 11
0
 public static string ResolveJson(this GraphQLGenerationOptions options, IValueNode value, ITypeNode typeNode, Document document)
 {
     return(options.ValueResolver.ResolveJson(value, typeNode, options, document));
 }
Exemplo n.º 12
0
 public EnumTypeContext(EnumTypeDefinition enumTypeDefinition, GraphQLGenerationOptions options, Document document)
 {
     this.enumTypeDefinition = enumTypeDefinition;
     this.options            = options;
     this.document           = document;
 }
Exemplo n.º 13
0
 public DirectiveContext(DirectiveDefinition directive, GraphQLGenerationOptions options, Document document)
 {
     this.directive = directive;
     this.options   = options;
     this.document  = document;
 }
Exemplo n.º 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));
 }
Exemplo n.º 15
0
 public UnionTypeContext(UnionTypeDefinition unionTypeDefinition, GraphQLGenerationOptions options)
 {
     this.unionTypeDefinition = unionTypeDefinition;
     this.options             = options;
 }
Exemplo n.º 16
0
 public string Resolve(ITypeNode typeNode, GraphQLGenerationOptions options, Document document, bool nullable = true)
 {
     return(GetTypeName(typeNode, options, document, nullable));
 }
Exemplo n.º 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;
Exemplo n.º 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));
        }
Exemplo n.º 20
0
 public InterfaceTypeContext(InterfaceTypeDefinition interfaceTypeDefinition, GraphQLGenerationOptions options, Document document)
 {
     this.declaration = interfaceTypeDefinition;
     this.options     = options;
     this.document    = document;
 }
Exemplo n.º 21
0
 public ScalarTypeContext(ScalarTypeDefinition definition, GraphQLGenerationOptions options)
 {
     this.definition = definition;
     this.options    = options;
 }