New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@influential/elm-graphql

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@influential/elm-graphql - npm Package Compare versions

Comparing version

to
1.6.0

80

lib/query-to-elm.js

@@ -155,2 +155,13 @@ /**

if (enums === void 0) { enums = {}; }
// Scan operation variables for enums.
if (def.kind == 'OperationDefinition') {
var operationDef = def;
if (operationDef.variableDefinitions) {
for (var _i = 0, _a = operationDef.variableDefinitions; _i < _a.length; _i++) {
var varDef = _a[_i];
var schemaType = utilities_1.typeFromAST(schema, varDef.type);
collectEnumsForType(schemaType, enums);
}
}
}
var info = new utilities_1.TypeInfo(schema);

@@ -234,3 +245,3 @@ language_1.visit(doc, {

if (def.operation == 'query' || def.operation == 'mutation') {
var decls = [];
var decls_1 = [];
// Name

@@ -244,6 +255,6 @@ var name_7;

}
var resultType = name_7[0].toUpperCase() + name_7.substr(1);
var responseType = resultType;
var resultType_1 = name_7[0].toUpperCase() + name_7.substr(1);
var responseType = resultType_1;
if (errorSpec) {
responseType = "(Response " + resultType + ")";
responseType = "(Response " + resultType_1 + ")";
}

@@ -254,3 +265,3 @@ // todo: Directives

// todo: use spreads...
decls.push(new elm_ast_1.ElmTypeAliasDecl(resultType, new elm_ast_1.ElmTypeRecord(fields)));
decls_1.push(new elm_ast_1.ElmTypeAliasDecl(resultType_1, new elm_ast_1.ElmTypeRecord(fields)));
// VariableDefinition

@@ -277,10 +288,39 @@ var parameters = [];

query += language_1.print(def);
var decodeFuncName = resultType[0].toLowerCase() + resultType.substr(1) + 'Decoder';
var decodeFuncName = resultType_1[0].toLowerCase() + resultType_1.substr(1) + 'Decoder';
expose.push(funcName);
expose.push(resultType);
var elmParamsType = new elm_ast_1.ElmTypeRecord(parameters.map(function (p) { return new elm_ast_1.ElmFieldDecl(p.name, p.type); }));
var elmParams = new elm_ast_1.ElmParameterDecl('params', elmParamsType);
var elmParamsDecl = elmParamsType.fields.length > 0 ? [elmParams] : [];
expose.push(resultType_1);
var elmParamsType = new elm_ast_1.ElmTypeRecord(parameters.map(function (p) {
var schemaType = p.schemaType;
if (schemaType instanceof type_1.GraphQLNonNull) {
schemaType = schemaType['ofType'];
}
if (schemaType instanceof type_1.GraphQLList) {
schemaType = schemaType['ofType'];
}
if (schemaType instanceof type_1.GraphQLNonNull) {
schemaType = schemaType['ofType'];
}
if (schemaType instanceof type_1.GraphQLScalarType) {
return new elm_ast_1.ElmFieldDecl(p.name, p.type);
}
else {
// Generate type for input object
var name_10 = resultType_1 + "_Input_" + p.name[0].toUpperCase() + p.name.substr(1);
decls_1.push(new elm_ast_1.ElmTypeAliasDecl(name_10, p.type, []));
expose.push(name_10);
// Reference generated type
return new elm_ast_1.ElmFieldDecl(p.name, new elm_ast_1.ElmTypeName(resultType_1 + "_Input_" + p.name[0].toUpperCase() + p.name.substr(1)));
}
}));
// Expose / reference input type for query
var elmParamsDecl = [];
if (elmParamsType.fields.length > 0) {
var elmParams = new elm_ast_1.ElmParameterDecl('params', new elm_ast_1.ElmTypeName(resultType_1 + "_Input"));
elmParamsDecl = [elmParams];
var paramName = resultType_1 + "_Input";
decls_1.push(new elm_ast_1.ElmTypeAliasDecl(paramName, elmParamsType, []));
expose.push(paramName);
}
var methodParam = def.operation == 'query' ? "\"" + verb + "\" " : '';
decls.push(new elm_ast_1.ElmFunctionDecl(funcName, elmParamsDecl, new elm_ast_1.ElmTypeName("Http.Request " + responseType), {
decls_1.push(new elm_ast_1.ElmFunctionDecl(funcName, elmParamsDecl, new elm_ast_1.ElmTypeName("Http.Request " + responseType), {
// we use awkward variable names to avoid naming collisions with query parameters

@@ -308,6 +348,6 @@ expr: ("let graphQLQuery = \"\"\"" + query.replace(/\s+/g, ' ') + "\"\"\" in\n") +

}));
var resultTypeName = resultType[0].toUpperCase() + resultType.substr(1);
decls.push(new elm_ast_1.ElmFunctionDecl(decodeFuncName, [], new elm_ast_1.ElmTypeName('Decoder ' + resultTypeName), query_to_decoder_1.decoderForQuery(def, info, schema, fragmentDefinitionMap, seenFragments)));
var resultTypeName = resultType_1[0].toUpperCase() + resultType_1.substr(1);
decls_1.push(new elm_ast_1.ElmFunctionDecl(decodeFuncName, [], new elm_ast_1.ElmTypeName('Decoder ' + resultTypeName), query_to_decoder_1.decoderForQuery(def, info, schema, fragmentDefinitionMap, seenFragments)));
info.leave(def);
return decls;
return decls_1;
}

@@ -329,4 +369,4 @@ }

var fields = type.getFields();
for (var name_10 in fields) {
var field = fields[name_10];
for (var name_11 in fields) {
var field = fields[name_11];
var valuePath = value + '.' + field.name;

@@ -473,4 +513,4 @@ fieldEncoders.push("(\"" + field.name + "\", " + encoderForInputType(field.type, false, valuePath) + ")");

var spread = sel;
var name_11 = spread.name.value;
var frag = fragmentDefinitionMap[name_11];
var name_12 = spread.name.value;
var frag = fragmentDefinitionMap[name_12];
info.enter(frag);

@@ -494,4 +534,4 @@ var _d = walkSelectionSet(frag.selectionSet, info), fields = _d[0], spreads = _d[1];

var args = [];
for (var name_12 in typeMap) {
args.push(typeMap[name_12]);
for (var name_13 in typeMap) {
args.push(typeMap[name_13]);
}

@@ -498,0 +538,0 @@ return new elm_ast_1.ElmTypeApp(union.name, args);

{
"name": "@influential/elm-graphql",
"version": "1.5.0",
"version": "1.6.0",
"description": "Elm code generator for GraphQL",

@@ -5,0 +5,0 @@ "main": "lib/main.js",

@@ -218,2 +218,14 @@ /**

function collectEnums(def: Definition, enums: GraphQLEnumMap = {}): GraphQLEnumMap {
// Scan operation variables for enums.
if(def.kind == 'OperationDefinition') {
let operationDef = <OperationDefinition> def;
if (operationDef.variableDefinitions) {
for (let varDef of operationDef.variableDefinitions) {
let schemaType = typeFromAST(schema, varDef.type);
collectEnumsForType(schemaType, enums);
}
}
}
let info = new TypeInfo(schema);

@@ -342,5 +354,43 @@ visit(doc, {

let elmParamsType = new ElmTypeRecord(parameters.map(p => new ElmFieldDecl(p.name, p.type)));
let elmParams = new ElmParameterDecl('params', elmParamsType);
let elmParamsDecl = elmParamsType.fields.length > 0 ? [elmParams] : [];
let elmParamsType = new ElmTypeRecord(parameters.map(p => {
let schemaType = p.schemaType;
if (schemaType instanceof GraphQLNonNull) {
schemaType = schemaType['ofType']
}
if (schemaType instanceof GraphQLList) {
schemaType = schemaType['ofType']
}
if (schemaType instanceof GraphQLNonNull) {
schemaType = schemaType['ofType']
}
if (schemaType instanceof GraphQLScalarType) {
return new ElmFieldDecl(p.name, p.type);
} else {
// Generate type for input object
let name = resultType + "_Input_" + p.name[0].toUpperCase() + p.name.substr(1);
decls.push(new ElmTypeAliasDecl(name, p.type, []));
expose.push(name);
// Reference generated type
return new ElmFieldDecl(p.name, new ElmTypeName(resultType + "_Input_" + p.name[0].toUpperCase() + p.name.substr(1)));
}
}));
// Expose / reference input type for query
let elmParamsDecl = [];
if(elmParamsType.fields.length > 0) {
let elmParams = new ElmParameterDecl('params', new ElmTypeName(resultType + "_Input"));
elmParamsDecl = [elmParams];
let paramName = resultType + "_Input";
decls.push(new ElmTypeAliasDecl(paramName, elmParamsType, []));
expose.push(paramName);
}
let methodParam = def.operation == 'query' ? `"${verb}" ` : '';

@@ -347,0 +397,0 @@