Comments (17)
I actually started working on a graphql-codegen plugin already. My intent is to replace the CLI entirely with it. The plugin could optionally generate the resolvers using the existing typescript-resolvers plugin as well to make the whole DX better.
from sqlmancer.
I adapted my project to the 0.2.1 release
And it works great, aside from the count.
I use @many, @paginate, typescript generation
It could me mentioned in the docs, how to integrate types:
client.ts:
import Knex from 'knex'
import { createSqlmancerClient } from 'sqlmancer'
import { SqlmancerClient } from './generated'
const knex = Knex({
client: 'pg',
connection: process.env.PG_CONNECTION_STRING,
})
export const client: SqlmancerClient = createSqlmancerClient('./src/sqlmancer/schema.ts', knex)
npx sqlmancer generate ./src/sqlmancer/schema.ts ./src/sqlmancer/generated.ts
context.d.ts:
import { Request, Response } from 'express'
import { SqlmancerClient } from '../sqlmancer/generated'
export type Context = { sql: any; req: Request; res: Response; client: SqlmancerClient }
server.ts:
import { makeSqlmancerSchema } from 'sqlmancer'
import { resolvers } from './resolvers'
import { schema } from '~/sqlmancer/schema'
import { client } from '~/sqlmancer/client'
const server = new ApolloServer({
schema: makeSqlmancerSchema({
typeDefs: schema,
resolvers: resolvers,
}),
context: ({ req, res }) => {
return {
sql,
client,
req,
res,
}
},
debug: false,
})
I still use one schema file because of code-gen.
I can try to write code-gen plugin ?
from sqlmancer.
The original intent behind the count
aggregate field was to answer questions like "how many orders have a status of DELIVERED?"
query {
orders(where: { status: { equal: "DELIVERED" } }) {
aggregate {
count
}
}
}
It sounds like we need to add a separate totalCount
field, probably next to hasMore
instead of inside the aggregate
object, that would return the count without the limit applied.
from sqlmancer.
So I understand the intend that functions that are inside aggregate to operate with all the arguments applied including limit and offset. And it is useful in case that results are not requested. Because if results are requested, it could be just calculated by the requester.
You intend to put totalCount outside aggregate. And it would not be affected by offset and limit. BTW hasMore is affected by offset. And these specs are implicit, is it good enough?
Furthermore, would there be need to calculate totalAvg/totalMin/totalMax ?
Considering the above, hasura's API seems reasonable. All can be done in one go. Just the where: $where need to be specified in each.
query {
orders(limit, where)
aggregate_orders(limit, where)
aggregate_orders(nolimit, where)
}
from sqlmancer.
Maybe like this
query {
orders(where: { status: { equal: "DELIVERED" } }) {
aggregate {
count
}
aggregateTotal {
count
}
}
}
from sqlmancer.
Or to be explicit:
query {
orders {
results(where: $where, offset: $offset, limit: $limit)
hasMore(where: $where, offset: $offset)
aggregate(where: $where, offset: $offset, limit: $limit ) {
count
}
aggregateTotal(where: $where) {
count
}
}
}
from sqlmancer.
totalCount
would really be more a convenience. It's already possible to do something like
query($where: OrderWhere!, $limit: Int!) {
orders(where: $where, limit: $limit) {
results {
id
}
}
allOrders: orders(where: $where) {
aggregate {
count
}
}
}
Definitely need to at least document the usage better.
By the way, I forgot to mention, you can simplify this:
client.models.Order.paginate().count().selectAll().resolveInfo(info).execute()
to just
client.models.Order.paginate().resolveInfo(info).execute()
resolveInfo
will append count
and select
and whatever other methods to the builder as needed depending on what fields are actually requested
from sqlmancer.
Thanks.
The above
query($where: OrderWhere!, $limit: Int!) {
orders(where: $where, limit: $limit) {
results {
id
}
}
allOrders: orders(where: $where) {
aggregate {
count
}
}
}
Indeed I do it now - as ordersCount. But it has to be added to the scheme.
from sqlmancer.
And btw date now returns a string - cool!
from sqlmancer.
Indeed I do it now - as ordersCount. But it has to be added to the scheme.
My mistake, you mean allOrders is an alias. Cool idea, then all good, no need for totalCount and such
from sqlmancer.
So essentially this issue can be closed
from sqlmancer.
I'm still wondering if adding totalCount
might make sense. It's not uncommon to see that field exposed in, for example, Relay connections.
from sqlmancer.
Each table will use this. At least, totalCount will simplify a bit the query.
But if it is related to Relay, it can be done together with #46
from sqlmancer.
It can be right now partly compatible with relay :))
hasMore -> pageInfo { hasNextPage }
results -> edges
from sqlmancer.
Implemented with 32fe4be
from sqlmancer.
@lishine a graphql-codegen
plugin is now available.
from sqlmancer.
Fantastic! I will test it
from sqlmancer.
Related Issues (20)
- graphql-toolkit is now deprecated in favor of graphql-tools
- The Node interface and globally unique IDs HOT 1
- Missing directives (NestJS integration) HOT 6
- add sybase support
- [RFC] Changes to the existing API and workflow HOT 12
- Issue when using esModuleInterop option HOT 3
- Trouble adding `@paginate` directives HOT 3
- Allow passing a schema directly to createSqlmancerClient
- Hitting some issues with one to many relations and retreiving specific fields HOT 2
- Ability to specify default and maximum limit values
- Customizable argument and input field names
- Suggestion: Expose join API on Builder Class HOT 3
- Depend on not passing field to the resolver unless in the query HOT 3
- Add ability to mock database results
- tion
- CTE in WHERE clause is empty HOT 1
- Join by multiple fields HOT 1
- https://sqlmancer.netlify.app/ is dead
- Allow composite primary keys HOT 1
- Is there a Roadmap? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlmancer.