Comments (7)
Was working on this issue tonight. I didn't feel convinced. Problem was that GraphQL is a concept that includes context and schema. And while it is a transport agnostic technology it feels temping to say also includes server, in practice, when working on a real project.
Compare for example:
graphql/
server.ts
context.ts
schema.ts
prisma/
schema.prisma
vs
src/
server.ts
context.ts
graphql.ts
prisma/
schema.prisma
I currently prefer the former:
- Root level
graphql
stands our more quickly when parsing project tree (e.g. a git repo wheregraphql
would be visible without any navigation). graphql/{context.ts,schema.ts}
is accurategraphql/ prisma/
feels like the right peer balance. When talking about the the stack, this is how it will often be seen: a graphql box and a prisma boxsrc/ prisma/
on the other hand is a bit odd––schema.prisma
contains "source code" too, it's just a declarative data modelling language instead of TypeScript. Splitting hairs over what is src or not just seems a waste of time and energy, without really giving value to the mental model.
CC @Weakky
from graphql-framework-experiment.
The problem with having a top-level graphql
, is that it assumes the users' codebase will only be about graphql although their codebase might be about thousand of other things.
And if we don't have a top-level folder to encapsulate graphql
, we'll force users to have their rootDir
be .
eg:
graphql/
User.ts
Post.ts
rest/
user.ts
post.ts
jobs/
job1.ts
job2.ts
prisma/
schema.prisma
Therefore, I suggest the following:
src/
graphql/
User.ts
Post.ts
index.ts //or main.ts
prisma/
schema.prisma
where one could evolve to:
src/
graphql/
User.ts
Post.ts
rest/
user.ts
post.ts
jobs/
job1.ts
job2.ts
index.ts //or main.ts
prisma/
schema.prisma
Reasoning:
index|main.ts
: Because we're "just an api", users might customize their codebase and do more stuff than just spawning a http server. I think we need to be more general so that people can do more stuff in the conventional entrypoint. It could evolve for example to:
src/
graphql/
User.ts
Post.ts
server.ts
rest/
user.ts
post.ts
server.ts
index.ts //or main.ts, where `index.ts` could require `src/graphql/server.ts`
prisma/
schema.prisma
-
index|main.ts
: I don't think we should allow both. I think we should choose one or the other, or even another one.index.ts
might be more js idiomatic -
Where is the
context.ts
: Not sure yet. probably insrc/graphql/context.ts
And while it is a transport agnostic technology it feels temping to say also includes server, in practice, when working on a real project
I agree with your point. I think it feels less weird if it's something like index.ts
or main.ts
(instead of server.ts
). It's no longer explicitely defined as being a server, but rather the entrypoint of your project (which... spawns the server)
from graphql-framework-experiment.
@Weakky good points. You're also making the case though for not treating graphql
as an alias for schema
. After all a rule about schema
folder is that all sub-modules are assumed to be schema-contributing modules, auto-imported, which in your last code example server.ts
would not be.
I still don't feel great about src/ prisma/
. I would like something a bit higher level. api/ prisma/
or app/ prisma/
or pumpkins/ prisma/
for example.
The following is somewhat off-topic/new issue but somewhat related:
To further underscore the high-level-ness of project dir, I was thinking of outputting the build to node_modules/.build
(.pumpkins_build
pumpkins_app_build
, ...?) and then revisiting the idea of $ pumpkins boot
which 1) knows to look into node_modules/.build
and 2) knows to call the start
module $node node_modules/.pumpkins_app_build/start
from graphql-framework-experiment.
from graphql-framework-experiment.
Here is a case where it seems nice/ok. Currently it must be schema
but imagine we did support graphql
. Peer top-level folders prisma
and graphql
feels like it would be elegant and simple.
from graphql-framework-experiment.
In the minimal case when working with a single schema file, I can see how a singular graphql.ts
module would be nice, versus what we currently support:
from graphql-framework-experiment.
Discussions with @schickling @Weakky this week. We will go ahead with the change!
from graphql-framework-experiment.
Related Issues (20)
- TS error with inputObjectType default value when using with list=true
- write test for build showing esnext module type works
- nexus:dev reflection failed HOT 8
- Force include directories in build
- Field in interface not get type generated
- Roadmap is empty HOT 3
- @nexus/schema return wrong error object shape
- Empty errors in production environment
- queryField and mutationField not generating types when used in makeSchema HOT 1
- On main page there is broken link to new handbook of typescript
- No source map when debug
- Add connection to ContextAdderLens
- Missing multipart field ‘operations’ (and other related errors) HOT 1
- TypeError: cookieParser is not a function after upgrading to 0.26.1 HOT 1
- Build error using pnpm
- Parallel testing causes multiple servers on the same port, resulting in jest hanging and failing unpredictably
- unhandledRejection
- Announcing the Sunsetting of Nexus Framework and a New Focus on Nexus Schema
- How do You use socket.io
- [email protected] does not support @prisma/[email protected]
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 graphql-framework-experiment.