How to use the ast-types.builders.property function in ast-types

To help you get started, we’ve selected a few ast-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
if (!enumKey.match(enumRegex)) {
                enumKey = 'ENUM_' + enumKey;
            }

            values.push(b.property(
                'init',
                b.literal(enumKey),
                b.objectExpression([
                    b.property('init', b.identifier('value'), b.literal(enumValue.value)),
                    generateDescription(enumValue.description)
                ])
            ));
        }

        var typeDeclaration = b.objectExpression([
            b.property('init', b.identifier('name'), b.literal(model.name + capitalize(field.name))),
            generateDescription(field.description),
            b.property('init', b.identifier('values'), b.objectExpression(values))
        ]);

        return b.newExpression(
            b.identifier('GraphQLEnumType'),
            [typeDeclaration]
        );
    }
}
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
function generateField(field, type, parentName, parentModel) {
        if (field.isPrimaryKey && opts.relay) {
            return b.property('init', b.identifier('id'), b.callExpression(
                b.identifier('globalIdField'),
                [b.literal(parentName)]
            ));
        }

        var props = [
            b.property('init', b.identifier('type'), type || getType(field, parentModel)),
            generateDescription(field.description)
        ];

        if (field.resolve) {
            props.push(b.property('init', b.identifier('resolve'), field.resolve));
        }

        if (field.args) {
            props.push(field.args);
github rexxars / sql-to-graphql / steps / ast-builders / object.js View on Github external
function buildObject(obj) {
    var fields = [], key;
    for (key in obj) {
        fields.push(b.property('init', b.literal(key), castValue(obj[key])));
    }

    return b.objectExpression(fields);
}
github rexxars / sql-to-graphql / steps / ast-builders / query.js View on Github external
var primaryKey = getPrimaryKey(model) || {};
    var keyName = primaryKey.name;
    var keyType = typeMap[primaryKey.type];

    return b.objectExpression([
        b.property('init', b.identifier('type'), b.identifier(type.varName)),
        b.property('init', b.identifier('args'), b.objectExpression(keyName ? [
            b.property('init', b.identifier('id'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal(keyName)),
                b.property('init', b.identifier('type'), b.newExpression(
                    b.identifier('GraphQLNonNull'),
                    [b.identifier(keyType)]
                ))
            ]))
        ] : []))
    ].concat(opts.outputDir ? [b.property(
        'init',
        b.identifier('resolve'),
        buildResolver(type)
    )] : []));
};
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
function generateLimitOffsetArgs() {
        return b.property('init', b.identifier('args'), b.objectExpression([
            b.property('init', b.identifier('limit'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('limit')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ])),
            b.property('init', b.identifier('offset'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('offset')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ]))
        ]));
    }
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
function generateLimitOffsetArgs() {
        return b.property('init', b.identifier('args'), b.objectExpression([
            b.property('init', b.identifier('limit'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('limit')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ])),
            b.property('init', b.identifier('offset'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('offset')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ]))
        ]));
    }
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
function generateLimitOffsetArgs() {
        return b.property('init', b.identifier('args'), b.objectExpression([
            b.property('init', b.identifier('limit'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('limit')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ])),
            b.property('init', b.identifier('offset'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('offset')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ]))
        ]));
    }
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
function generateLimitOffsetArgs() {
        return b.property('init', b.identifier('args'), b.objectExpression([
            b.property('init', b.identifier('limit'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('limit')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ])),
            b.property('init', b.identifier('offset'), b.objectExpression([
                b.property('init', b.identifier('name'), b.literal('offset')),
                b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
            ]))
        ]));
    }