Socket
Socket
Sign inDemoInstall

graphql-genie

Package Overview
Dependencies
21
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.1 to 0.3.2

lib/GenerateGetOne.d.ts

4

docs/GraphQLGenieAPI.md

@@ -105,7 +105,9 @@ - [GraphQLGenie API](#graphqlgenie-api)

```
Returns data in the database, this will look a little different than what is returned by graphql. Every object will have a __typename field and relations will just be ids or an array of ids rather than objects. Also if you use interfaces and unions there may be null fields you weren't expecting on that type.
**types** - Optional. List of the GraphQL Object Types you want data for. If null or blank all data will be returned
**context** - Optional. Context object that will be sent to input/output hooks, may be needed if using the authentication plugin
Returns data in the database, this will look a little different than what is returned by graphql. Every object will have a __typename field and relations will just be ids or an array of ids rather than objects. Also if you use interfaces and unions there may be null fields you weren't expecting on that type. It will look something like:
It will look something like:

@@ -112,0 +114,0 @@ ```json

- [Queries](#queries)
- [Query docs](#query-docs)
- [where argument](#where-argument)
- [orderBy argument](#orderby-argument)
- [Examples](#examples)
- [Get all the cities](#get-all-the-cities)
- [Get a single city matching an id](#get-a-single-city-matching-an-id)
- [Get cities using a filter and skip](#get-cities-using-a-filter-and-skip)
- [Get cities and filter the output](#get-cities-and-filter-the-output)
- [Get One](#get-one)
- [Get All](#get-all)
- [Query docs](#query-docs)
- [Get One](#get-one-1)
- [Get All](#get-all-1)
- [where argument](#where-argument)
- [orderBy argument](#orderby-argument)
- [Examples](#examples)
- [Get all the cities](#get-all-the-cities)
- [Get a single city matching an id](#get-a-single-city-matching-an-id)
- [Get a single user matching a unique field](#get-a-single-user-matching-a-unique-field)
- [Get cities using a filter and skip](#get-cities-using-a-filter-and-skip)
- [Get cities and filter the output](#get-cities-and-filter-the-output)

@@ -16,2 +21,8 @@ # Queries

## Get One
If `generateGetOne` is true in the generatorOptions (defaults to true) queries will be created for every type in the model. The name of the query will be the camel case of the type name. Arguments are any unique fields and will return a single object from the data store
## Get All
If `generateGetAll` is true in the generatorOptions (defaults to true) queries will be created for every type in the model. The name of the query will be the plural version of the type name.

@@ -21,3 +32,3 @@

For the following typedefs `users` and `cities` queries will be created.
For the following typedefs `user`, `users`, `city` and `cities` queries will be created.

@@ -51,3 +62,16 @@ ```typescript

### Get One
The generated query will look like this, you can either use the where object or the root arguments
```graphql
user(
where: UserWhereUniqueInput
id: ID
displayname: String
email: String
): User
```
### Get All
Let's take a close look at what a generated query looks like

@@ -81,3 +105,3 @@

population: [Int!]
)
) : [City]
```

@@ -162,3 +186,3 @@

query singleCity {
cities (id: "ID") {
city (id: "ID") {
id

@@ -170,2 +194,13 @@ name

### Get a single user matching a unique field
```graphql
query singleUser {
user (displayname: "aCoreyJ") {
id
name
}
}
```
### Get cities using a filter and skip

@@ -172,0 +207,0 @@

@@ -5,2 +5,3 @@ import { isInterfaceType, isUnionType } from 'graphql';

import { getAllResolver, getRootMatchFields, queryArgs } from './TypeGeneratorUtilities';
import { camelCase } from 'lodash';
export class GenerateConnections {

@@ -61,3 +62,3 @@ constructor(dataResolver, objectName, types, $schema, $currOutputObjectTypeDefs, $currInputObjectTypes, $schemaInfo, $relations) {

this.types.forEach(type => {
const fieldName = `${pluralize(type.name.toLowerCase())}Connection`;
const fieldName = `${camelCase(pluralize(type.name))}Connection`;
this.createNewTypes(type.name);

@@ -64,0 +65,0 @@ const schemaType = this.schema.getType(type.name);

@@ -10,3 +10,3 @@ import { GraphQLFieldResolver, GraphQLInputType, GraphQLSchema, IntrospectionObjectType, IntrospectionType } from 'graphql';

private fields;
private resolvers;
resolvers: Map<string, GraphQLFieldResolver<any, any>>;
private currInputObjectTypes;

@@ -13,0 +13,0 @@ private schemaInfo;

@@ -12,2 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { getAllResolver, getRootMatchFields, queryArgs } from './TypeGeneratorUtilities';
import { camelCase } from 'lodash';
export class GenerateGetAll {

@@ -34,3 +35,3 @@ constructor(dataResolver, objectName, types, $schema, $currInputObjectTypes, $schemaInfo, $relations) {

}, queryArgs, getRootMatchFields(this.currInputObjectTypes.get(`${type.name}MatchInput`)));
const fieldName = `${pluralize(type.name.toLowerCase())}`;
const fieldName = `${camelCase(pluralize(type.name))}`;
this.fields[fieldName] = {

@@ -37,0 +38,0 @@ type: `[${type.name}]`,

@@ -22,5 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { computeRelations, getTypeResolver } from './TypeGeneratorUtilities';
import { GenerateGetOne } from './GenerateGetOne';
export class GraphQLGenie {
constructor(options) {
this.config = {
generateGetOne: true,
generateGetAll: true,

@@ -99,5 +101,10 @@ generateCreate: true,

const currOutputObjectTypeDefs = new Set();
let getAll;
if (this.config.generateGetAll) {
this.generators.push(new GenerateGetAll(this.graphQLFortune, 'Query', nodeTypes, this.schema, currInputObjectTypes, this.schemaInfo, this.relations));
getAll = new GenerateGetAll(this.graphQLFortune, 'Query', nodeTypes, this.schema, currInputObjectTypes, this.schemaInfo, this.relations);
this.generators.push(getAll);
}
if (this.config.generateGetOne) {
this.generators.push(new GenerateGetOne(this.graphQLFortune, 'Query', nodeTypes, this.schema, currInputObjectTypes, this.schemaInfo, this.relations, getAll));
}
if (this.config.generateConnections) {

@@ -104,0 +111,0 @@ this.generators.push(new GenerateConnections(this.graphQLFortune, 'Query', nodeTypes, this.schema, currOutputObjectTypeDefs, currInputObjectTypes, this.schemaInfo, this.relations));

@@ -47,2 +47,3 @@ import { GraphQLFieldResolver } from 'graphql';

export interface GenerateConfig {
generateGetOne?: boolean;
generateGetAll?: boolean;

@@ -49,0 +50,0 @@ generateCreate?: boolean;

@@ -5,3 +5,3 @@ import { GraphQLNonNull, getNamedType, isInputObjectType, isInputType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isSpecifiedDirective, isUnionType, print } from 'graphql';

import GraphQLJSON from 'graphql-type-json';
import { find, has, isEmpty, set, values } from 'lodash';
import { camelCase, find, has, isEmpty, set, values } from 'lodash';
import pluralize from 'pluralize';

@@ -139,5 +139,5 @@ import { getReturnType, typeIsList } from './GraphQLUtils';

else { // if an object type grab from existing query type
let queryFieldName = `${pluralize(returnType.name.toLowerCase())}`;
let queryFieldName = `${camelCase(pluralize(returnType.name))}`;
if (returnType.name.endsWith('Connection')) {
queryFieldName = `${pluralize(returnType.name.replace('Connection', '').toLowerCase())}Connection`;
queryFieldName = `${camelCase(pluralize(returnType.name.replace('Connection', '')))}Connection`;
}

@@ -144,0 +144,0 @@ const queryField = queryTypeFields[queryFieldName];

@@ -1,2 +0,2 @@

import { GraphQLInputType, GraphQLNamedType, GraphQLSchema, IntrospectionType } from 'graphql';
import { GraphQLInputObjectType, GraphQLInputType, GraphQLNamedType, GraphQLSchema, IntrospectionType } from 'graphql';
import { GenerateConfig } from './GraphQLGenieInterfaces';

@@ -19,3 +19,3 @@ import { Relations } from './TypeGeneratorUtilities';

private generateFieldForInput;
generateWhereUniqueInput(fieldType?: GraphQLNamedType): GraphQLInputType;
generateWhereUniqueInput(fieldType?: GraphQLNamedType): GraphQLInputObjectType;
private getWhereInput;

@@ -22,0 +22,0 @@ generateWhereInput(addLogicalOperators: boolean, fieldType?: GraphQLNamedType): GraphQLInputType;

import { GraphQLBoolean, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, getNamedType, getNullableType, isEnumType, isInputType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType } from 'graphql';
import { each, get, isEmpty, merge } from 'lodash';
import { camelCase, each, get, isEmpty, merge } from 'lodash';
import pluralize from 'pluralize';
import { getReturnType, typeIsList } from './GraphQLUtils';
import { Mutation, capFirst, fortuneFilters, lowerFirst } from './TypeGeneratorUtilities';
import { Mutation, capFirst, fortuneFilters } from './TypeGeneratorUtilities';
export class InputGenerator {

@@ -99,3 +99,3 @@ constructor($type, $config, $currInputObjectTypes, $schemaInfo, $schema, $relations, $dummy = false) {

const typeName = isArray ? pluralize(typeInfo.name) : typeInfo.name;
const fieldName = lowerFirst(typeName);
const fieldName = camelCase(typeName);
const fieldInputTypeName = typeInfo.name + fieldSuffix + capFirst(relationFieldName) + 'Input';

@@ -102,0 +102,0 @@ merge(fields, this.generateFieldForInput(fieldName, new GraphQLInputObjectType({ name: fieldInputTypeName, fields: {} })));

@@ -74,5 +74,4 @@ import { GraphQLArgument, GraphQLInputObjectType, GraphQLNamedType, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema, GraphQLType, IntrospectionObjectType, IntrospectionType } from 'graphql';

export declare const capFirst: (val: string) => string;
export declare const lowerFirst: (val: string) => string;
export declare const isConnectionType: (type: GraphQLType) => boolean;
export declare const getRecordFromResolverReturn: (record: any) => any;
//# sourceMappingURL=TypeGeneratorUtilities.d.ts.map

@@ -836,5 +836,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
export const lowerFirst = (val) => {
return val ? val.charAt(0).toLowerCase() + val.slice(1) : '';
};
export const isConnectionType = (type) => {

@@ -841,0 +838,0 @@ let isConnection = false;

{
"name": "graphql-genie",
"version": "0.3.1",
"version": "0.3.2",
"description": "GraphQL Genie",

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

@@ -36,3 +36,3 @@ import commonjs from 'rollup-plugin-commonjs';

namedExports: {
'node_modules/lodash/lodash.js': ['values', 'find', 'eq', 'difference', 'union', 'uniq', 'pick', 'isDate', 'startsWith', 'includes', 'omitBy', 'omit', 'set', 'has', 'isString', 'isEqual', 'findIndex', 'concat', 'forOwn', 'keyBy', 'assign', 'each', 'get', 'merge', 'pickBy', 'endsWith', 'isEmpty', 'isArray', 'isObject', 'map', 'keys', 'mapKeys', 'mapValues'],
'node_modules/lodash/lodash.js': ['camelCase', 'values', 'find', 'eq', 'difference', 'union', 'uniq', 'pick', 'isDate', 'startsWith', 'includes', 'omitBy', 'omit', 'set', 'has', 'isString', 'isEqual', 'findIndex', 'concat', 'forOwn', 'keyBy', 'assign', 'each', 'get', 'merge', 'pickBy', 'endsWith', 'isEmpty', 'isArray', 'isObject', 'map', 'keys', 'mapKeys', 'mapValues'],
'node_modules/graphql-tools/dist/index.js': [ 'SchemaDirectiveVisitor', 'makeExecutableSchema', 'addResolveFunctionsToSchema' ],

@@ -39,0 +39,0 @@ 'node_modules/graphql-type-json/lib/index.js': ['GraphQLJSON'],

@@ -7,3 +7,3 @@

import { Relations, getAllResolver, getRootMatchFields, queryArgs } from './TypeGeneratorUtilities';
import {camelCase} from 'lodash';
export class GenerateConnections implements TypeGenerator {

@@ -90,3 +90,3 @@ private objectName: string;

this.types.forEach(type => {
const fieldName = `${pluralize(type.name.toLowerCase())}Connection`;
const fieldName = `${camelCase(pluralize(type.name))}Connection`;

@@ -93,0 +93,0 @@ this.createNewTypes(type.name);

@@ -7,2 +7,3 @@

import { Relations, getAllResolver, getRootMatchFields, queryArgs } from './TypeGeneratorUtilities';
import {camelCase} from 'lodash';

@@ -15,3 +16,3 @@ export class GenerateGetAll implements TypeGenerator {

private fields: object;
private resolvers: Map<string, GraphQLFieldResolver<any, any>>;
public resolvers: Map<string, GraphQLFieldResolver<any, any>>;
private currInputObjectTypes: Map<string, GraphQLInputType>;

@@ -49,3 +50,3 @@ private schemaInfo: IntrospectionType[];

const fieldName = `${pluralize(type.name.toLowerCase())}`;
const fieldName = `${camelCase(pluralize(type.name))}`;

@@ -52,0 +53,0 @@ this.fields[fieldName] = {

@@ -16,2 +16,3 @@

import { Relations, computeRelations, getTypeResolver } from './TypeGeneratorUtilities';
import { GenerateGetOne } from './GenerateGetOne';

@@ -21,2 +22,3 @@ export class GraphQLGenie {

private config: GenerateConfig = {
generateGetOne: true,
generateGetAll: true,

@@ -137,6 +139,10 @@ generateCreate: true,

const currOutputObjectTypeDefs = new Set<string>();
let getAll;
if (this.config.generateGetAll) {
this.generators.push(new GenerateGetAll(this.graphQLFortune, 'Query', nodeTypes, this.schema, currInputObjectTypes, this.schemaInfo, this.relations));
getAll = new GenerateGetAll(this.graphQLFortune, 'Query', nodeTypes, this.schema, currInputObjectTypes, this.schemaInfo, this.relations);
this.generators.push(getAll);
}
if (this.config.generateGetOne) {
this.generators.push(new GenerateGetOne(this.graphQLFortune, 'Query', nodeTypes, this.schema, currInputObjectTypes, this.schemaInfo, this.relations, getAll));
}
if (this.config.generateConnections) {

@@ -143,0 +149,0 @@ this.generators.push(new GenerateConnections(this.graphQLFortune, 'Query', nodeTypes, this.schema, currOutputObjectTypeDefs, currInputObjectTypes, this.schemaInfo, this.relations));

@@ -63,2 +63,3 @@ import { GraphQLFieldResolver } from 'graphql';

export interface GenerateConfig {
generateGetOne?: boolean;
generateGetAll?: boolean;

@@ -65,0 +66,0 @@ generateCreate?: boolean;

@@ -6,3 +6,3 @@

import GraphQLJSON from 'graphql-type-json';
import { find, has, isEmpty, set, values } from 'lodash';
import { camelCase, find, has, isEmpty, set, values } from 'lodash';
import pluralize from 'pluralize';

@@ -195,5 +195,5 @@ import { GenerateConfig } from './GraphQLGenieInterfaces';

} else { // if an object type grab from existing query type
let queryFieldName = `${pluralize(returnType.name.toLowerCase())}`;
let queryFieldName = `${camelCase(pluralize(returnType.name))}`;
if (returnType.name.endsWith('Connection')) {
queryFieldName = `${pluralize(returnType.name.replace('Connection', '').toLowerCase())}Connection`;
queryFieldName = `${camelCase(pluralize(returnType.name.replace('Connection', '')))}Connection`;
}

@@ -200,0 +200,0 @@ const queryField = queryTypeFields[queryFieldName];

import { GraphQLBoolean, GraphQLEnumType, GraphQLField, GraphQLInputFieldConfigMap, GraphQLInputObjectType, GraphQLInputType, GraphQLList, GraphQLNamedType, GraphQLNonNull, GraphQLScalarType, GraphQLSchema, IntrospectionField, IntrospectionObjectType, IntrospectionType, getNamedType, getNullableType, isEnumType, isInputType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType } from 'graphql';
import { each, get, isEmpty, merge } from 'lodash';
import { camelCase, each, get, isEmpty, merge } from 'lodash';
import pluralize from 'pluralize';
import { GenerateConfig } from './GraphQLGenieInterfaces';
import { getReturnType, typeIsList } from './GraphQLUtils';
import { Mutation, Relations, capFirst, fortuneFilters, lowerFirst } from './TypeGeneratorUtilities';
import { Mutation, Relations, capFirst, fortuneFilters } from './TypeGeneratorUtilities';
export class InputGenerator {

@@ -107,3 +107,3 @@

const typeName = isArray ? pluralize(typeInfo.name) : typeInfo.name;
const fieldName = lowerFirst(typeName);
const fieldName = camelCase(typeName);
const fieldInputTypeName = typeInfo.name + fieldSuffix + capFirst(relationFieldName) + 'Input';

@@ -160,3 +160,3 @@ merge(fields, this.generateFieldForInput(

generateWhereUniqueInput(fieldType: GraphQLNamedType = this.type): GraphQLInputType {
generateWhereUniqueInput(fieldType: GraphQLNamedType = this.type): GraphQLInputObjectType {
const name = fieldType.name + 'WhereUniqueInput';

@@ -192,3 +192,3 @@ if (!this.currInputObjectTypes.has(name)) {

}
return this.currInputObjectTypes.get(name);
return <GraphQLInputObjectType>this.currInputObjectTypes.get(name);
}

@@ -195,0 +195,0 @@

@@ -113,2 +113,22 @@ import { ApolloClient } from 'apollo-client';

test('find singular - make sure user also has post', async () => {
const user = gql`
query user($id: ID){
user(id: $id) {
id
writtenSubmissions {
id
}
}
}
`;
const result = await client.query({
query: user,
variables: { id: testData.users[0].id }
});
expect(result.data['user'].id).toBe(testData.users[0].id);
expect(result.data['user'].writtenSubmissions[0].id).toBe(testData.posts[0].id);
});
test('create - post with new user', async () => {

@@ -115,0 +135,0 @@ const $title = 'Genie is more than great';

@@ -908,6 +908,2 @@ import { GraphQLArgument, GraphQLInputObjectType, GraphQLList, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema, GraphQLType, IntrospectionObjectType, IntrospectionType, defaultFieldResolver, getNamedType, isEnumType, isInterfaceType, isObjectType, isScalarType, isUnionType } from 'graphql';

export const lowerFirst = (val: string) => {
return val ? val.charAt(0).toLowerCase() + val.slice(1) : '';
};
export const isConnectionType = (type: GraphQLType): boolean => {

@@ -914,0 +910,0 @@ let isConnection = false;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc