private string? ProcessJsonToken()

in src/Core/Generator/SchemaGenerator.cs [212:293]


        private string? ProcessJsonToken(JsonElement token, string fieldName, string parentType, bool isArray, int parentArrayLength = 1)
        {
            parentType = parentType.Pascalize();

            string? gqlFieldType = "String";
            // If field name is "id" then it will be represented as ID in GQL
            if (fieldName == "id")
            {
                gqlFieldType = "ID";
            }
            else
            {
                // Rest of the fields will be processed based on their type
                switch (token.ValueKind)
                {
                    case JsonValueKind.Object:
                    {
                        string objectTypeName = fieldName.Pascalize();

                        if (isArray)
                        {
                            objectTypeName = objectTypeName.Singularize();
                        }

                        if (_entityAndSingularNameMapping.Count == 0 ||
                            (_entityAndSingularNameMapping.Count != 0 && _entityAndSingularNameMapping.ContainsKey(objectTypeName)))
                        {
                            // Recursively traverse nested objects.
                            this.TraverseJsonObject(JsonDocument.Parse(token.GetRawText()), objectTypeName);
                            gqlFieldType = objectTypeName;
                        }
                        else
                        {
                            gqlFieldType = null;
                        }

                        break;
                    }
                    case JsonValueKind.Array:
                        gqlFieldType = this.ProcessJsonArray(token, fieldName, parentType.Singularize());
                        break;

                    case JsonValueKind.Number:
                        if (token.TryGetInt32(out int _))
                        {
                            gqlFieldType = "Int";
                        }
                        else if (token.TryGetDouble(out double _))
                        {
                            gqlFieldType = "Float";
                        }

                        break;
                    case JsonValueKind.True:
                    case JsonValueKind.False:
                        gqlFieldType = "Boolean";
                        break;
                    case JsonValueKind.Null or JsonValueKind.String:
                        if (DateTime.TryParse(token.GetString(), DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out DateTime _))
                        {
                            gqlFieldType = "Date";
                        }
                        else
                        {
                            // Assuming string if attribute is NULL or not a date
                            gqlFieldType = "String";
                        }

                        break;
                    default:
                        throw new InvalidOperationException($"Unsupported token.ValueKind: {token.ValueKind}");
                }
            }

            // Add or update attribute information in the entity mapping.
            if (gqlFieldType != null)
            {
                this.AddOrUpdateAttributeInfo(token, fieldName, parentType, isArray, gqlFieldType, parentArrayLength);
            }

            return gqlFieldType;
        }