How to use the ast-types.builders.newExpression 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
function getType(field, model) {
        if (field.type === 'enum') {
            addUsedType('GraphQLEnumType');
            return getEnum(field, model);
        }

        var type = typeMap[field.type];
        var identifier = b.identifier(type);

        addUsedType(type);

        if (!field.isNullable) {
            addUsedType('GraphQLNonNull');
            return b.newExpression(b.identifier('GraphQLNonNull'), [identifier]);
        }

        return identifier;
    }
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
);

        var typeDeclaration = b.objectExpression([
            b.property('init', b.identifier('name'), b.literal(name)),
            generateDescription(model.description),
            b.property(
                'init',
                b.identifier('fields'),
                buildFieldWrapperFunction(name, b.objectExpression(fields), opts)
            )
        ].concat(interfaces || []));

        return {
            ast: buildVar(
                name + 'Type',
                b.newExpression(
                    b.identifier('GraphQLObjectType'),
                    [typeDeclaration]
                ),
                opts.es6
            )
        };
    }
github rexxars / sql-to-graphql / steps / ast-builders / query.js View on Github external
module.exports = function buildQuery(type, data, opts) {
    var model = data.models[type.name];
    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 paeckchen / paeckchen / packages / paeckchen-core / src / modules.ts View on Github external
function wrapMissingModule(modulePath: string): Promise {
  return Promise.resolve(b.program([
    b.throwStatement(
      b.newExpression(
        b.identifier('Error'),
        [
          b.literal(`Module '${modulePath}' not found`)
        ]
      )
    )
  ]));
}
github rexxars / sql-to-graphql / steps / ast-builders / schema.js View on Github external
return b.property(
                'init',
                b.identifier(camelCase(type.name)),
                buildQuery(type, data, opts)
            );
        });
    }

    return buildVar('schema',
        b.newExpression(
            b.identifier('GraphQLSchema'),
            [b.objectExpression([
                b.property(
                    'init',
                    b.identifier('query'),
                    b.newExpression(
                        b.identifier('GraphQLObjectType'),
                        [b.objectExpression([
                            b.property('init', b.identifier('name'), b.literal('RootQueryType')),
                            b.property('init', b.identifier('fields'), buildFieldWrapperFunction(
                                'RootQuery',
                                b.objectExpression(queryFields),
                                opts
                            ))
                        ])]
                    )
                )
            ])]
        )
    );
};
github rexxars / sql-to-graphql / steps / ast-builders / schema.js View on Github external
'init',
            b.identifier('node'),
            b.identifier('nodeField')
        ));
    } else {
        queryFields = map(data.types, function(type) {
            return b.property(
                'init',
                b.identifier(camelCase(type.name)),
                buildQuery(type, data, opts)
            );
        });
    }

    return buildVar('schema',
        b.newExpression(
            b.identifier('GraphQLSchema'),
            [b.objectExpression([
                b.property(
                    'init',
                    b.identifier('query'),
                    b.newExpression(
                        b.identifier('GraphQLObjectType'),
                        [b.objectExpression([
                            b.property('init', b.identifier('name'), b.literal('RootQueryType')),
                            b.property('init', b.identifier('fields'), buildFieldWrapperFunction(
                                'RootQuery',
                                b.objectExpression(queryFields),
                                opts
                            ))
                        ])]
                    )
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
function generateListReferenceField(reference) {
        addUsedType('GraphQLList');

        if (opts.relay) {
            return generateRelayReferenceField(reference);
        }

        return generateField({
            name: reference.field,
            description: reference.description || opts.defaultDescription + ' (reference)',
            resolve: buildResolver(reference.model, find(reference.model.fields, { isPrimaryKey: true }).originalName),
            args: generateLimitOffsetArgs()
        }, b.newExpression(
            b.identifier('GraphQLList'),
            [b.callExpression(b.identifier('getType'), [b.literal(reference.model.name)])]
        ));
    }
github rexxars / sql-to-graphql / steps / generate-types.js View on Github external
'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]
        );
    }
}