Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination #3

Open
jmaicaaan opened this issue Jun 22, 2018 · 8 comments
Open

Pagination #3

jmaicaaan opened this issue Jun 22, 2018 · 8 comments

Comments

@jmaicaaan
Copy link
Member

Ability to filter, sort, offset or order by a collection

@ghost
Copy link

ghost commented Jun 23, 2018

Hi, I think pagination and skipping is achievable using grapql. The problem that I've encountered is that I don't know how to have an input type of dynamic object, we can use that in where field of filter, since where should be dynamic. Is it possible to have Dynamic object type on this point of time? I did not go on that deeply. Leave your comments below @jmaicaaan @isotopeee

@jmaicaaan
Copy link
Member Author

Hmm, how do you define the dynamic input object? I think the GraphQL input type is strictly typed to its schema. Moving forward, the where property in the filter should also the same as the fields in its schema too.
For example, if you have a fields like this

{
	id: { type: GraphQLID },
	name: { type: GraphQLString },
	email: { type: GraphQLString },
	address: { type: AddressInputType }
}

The where filter should also based from it. I think having a dynamic input object breaks the power of a strongly typed schema provided by GraphQL. Here is the sample of how I changed your user.type.js in my local.

user.type.js

const {
	GraphQLObjectType,
	GraphQLString,
	GraphQLID,
	GraphQLInputObjectType
} = require('graphql');

const AddressFields = {
	city: { type: GraphQLString },
	zipcode: { type: GraphQLString }
};

const AddressType = new GraphQLObjectType({
  name: 'Address',
  fields: () => ({
    ... AddressFields
  })
});

const AddressInputType = new GraphQLInputObjectType({
	name: 'AddressInputType',
	description: 'Address payload definition',
	fields: () => ({
		... AddressFields
	})
})

const UserFields = {
	id: { type: GraphQLID },
	name: { type: GraphQLString },
	email: { type: GraphQLString },
	address: { type: AddressType }
};

const UserInputFields = {
	id: { type: GraphQLID },
	name: { type: GraphQLString },
	email: { type: GraphQLString },
	address: { type: AddressInputType }
};

const UserType = new GraphQLObjectType({
	name: 'User',
	fields: () => ({
		... UserFields
	})
});

const UserInputType = new GraphQLInputObjectType({
	name: 'UserInputType',
	description: 'User payload definition',
	fields: () => ({
		... UserInputFields
	})
})

module.exports = { 
	AddressType,
	UserType,
	UserInputType,
	AddressInputType
}

user.query.js

const { UserType, UserInputType } = require('./user.type');

const FilterType = new GraphQLInputObjectType({
  name: 'Filter',
  fields: () => ({
    limit: { type: GraphQLInt },
    skip: { type: GraphQLInt },
    order: { type: GraphQLString },
    where: { type: UserInputType }
  })
});

@jmaicaaan
Copy link
Member Author

If the comment above confused you, I pushed those changes into another branch just to show it to you https://github.com/UltraRangers/graphql-playground/tree/hotfix/pagination-v2.

@ghost
Copy link

ghost commented Jun 24, 2018

That is probably strongly typed, I dont think Input shouldn't be always strongly typed, well it is good and safe if on mutation, but not on querying. Or maybe I didn't know it yet. But how can we use a complex object filter that does have include property or an { eq: } value. I anticipate that we will use ORM and they probably have different implementation of querying so I think we should go on dynamically typed rather than pure strongly typed

@jmaicaaan
Copy link
Member Author

But but those filter are already defined. I think what will satisfy the filter of the ORM will be created in the schema of graphql. I dont think the graphql is a dynamic driven schema.

@isotopeee
Copy link

Hi @cedrickmandocdoc, you might want to take a look at the Variables, Fragment and Directives section of the docs. I think it's the mechanisms for dynamic queries while still getting the benefits of a strongly typed schema. @jmaicaaan correct me if I'm wrong.

@jmaicaaan
Copy link
Member Author

Hmm i'm not really sure about that. Havent used those things yet. But after taking a quick look, it is still using the same exact fields which are defined in the schema. If I understand @cedrickmandocdoc 's situation, he needs to have a dynamic fields of inq, gte, lte, includes (loopback) without having to define in the schema. Just pass it to the orm's function. So he doesn't have to construct those fields in the schema.
Is that correct @cedrickmandocdoc?

@isotopeee
Copy link

@cedrickmandocdoc , @jmaicaaan , check out this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants