yoga2 icon indicating copy to clipboard operation
yoga2 copied to clipboard

Move graphql folder out of src

Open maticzav opened this issue 5 years ago β€’ 5 comments

I have mixed opinion about having src folder because next omits that all together as well and it seems genuinely clearer for a framework with a fixed structure. I don't know whether this might be important for TS to work as expected, but I believe it is possible to get that running as well.

I believe it would be really cool if you could have Next and Yoga, for example, in the same folder and simply have pages and graphql folder. Having src folder for Yoga kind of brakes that because then there’s this src which adds to the vagueness of where to start reading the source. The idea of having all of them in the same folder sounds very nostalgic to all the great features of GraphCool which I believe attracted many other people as well.

cc @schickling

maticzav avatar Feb 27 '19 23:02 maticzav

Are you proposing that the src folder be removed (and only a graphql folder containing types) be in the root? Or that the graphql be alongside the src folder?

DevanB avatar Feb 28 '19 02:02 DevanB

@DevanB, sorry for a vague explanation. Indeed, I am proposing that we remove the src folder by default. Nevertheless, users could still have it for other purposes or could configure root to point to a particular folder in the yoga config. (That's why I titled the issue "moving graphql out of src".)

maticzav avatar Feb 28 '19 07:02 maticzav

Hey @maticzav πŸ‘‹,

I like your proposal, does the tree below properly sums up the tree structure you're describing?

.
β”œβ”€β”€ graphql
β”‚   β”œβ”€β”€ context.ts // (optional)
β”‚   β”œβ”€β”€ resolvers
β”‚   β”‚   β”œβ”€β”€ Mutation.ts
β”‚   β”‚   └── Query.ts
β”‚   └── server.ts // (optional)
β”œβ”€β”€ package.json
└── pages
    β”œβ”€β”€ ComponentA.tsx
    └── ComponentB.tsx

I added a resolvers folder to properly separate the additional files that you might have and your actual resolvers. Flattening every might be a better option, I don't know, the tree below feels weird to me:

.
β”œβ”€β”€ graphql
β”‚   β”œβ”€β”€ Mutation.ts
β”‚   β”œβ”€β”€ Query.ts
β”‚   β”œβ”€β”€ context.ts
β”‚   └── server.ts
β”œβ”€β”€ package.json
└── pages
    β”œβ”€β”€ ComponentA.tsx
    └── ComponentB.tsx

What do you think?

Weakky avatar Mar 01 '19 14:03 Weakky

@Weakky the first option seems excellent. I like the separation of concepts and folder names do their job very well. I also added my initial idea below, but I think your suggestion might do an even better job. Could you maybe also add the database (prisma) files?

screenshot 2019-03-01 at 15 25 36

I also added yoga-config.ts, yoga-context.ts and yoga-server.ts files which are all inspired by how GatsbyJS handles configuration files as opposed to keeping them in the folder (names explain their purpose). I like this approach because it feels like you are only working on frontend even though there's a significant amount of logic that you can put in the resolvers. Besides that, I believe it feels more natural to have an additional resolvers folder which holds more complex structures alongside the graphql folder (similar to components and pages).

I think it would be fascinating to compare the folder structure of Yoga alongside NextJS and GatsbyJS which I believe will be used most frequently together.

maticzav avatar Mar 01 '19 14:03 maticzav

little disclaimer: i just stumbled across this repo and i'm quite interested in this, so maybe you already considered my thoughts on this πŸ˜„. Anyway thank you for creating such beautiful and fun to use GraphQL solutions πŸ‘ .

@Weakky you can see in @maticzav reply that he also separates yoga-server from the graphql folder. My proposal would be to give the developer the freedom of choosing where certain modules of his yoga2 application can be found.

screenshot 2019-03-01 at 15 25 36

'Hardcoding' paths and names like the parent folder 'graphql' seems reasonable at first, however we can't ever be sure that a developer would name this folder exactly this way and keep this folder structure for each project he has (See the False consensus effect).

For example: a developer could or might want to for example also just call this parent folder frontend-api to make clear, that this is the interface for the frontend to communicate with the backend while separating his resolvers into a /Query/ and /Mutation/ folder respectively.

I think default values are fine for people which don't want to configure a lot or just use the boilerplate to get started, but quite a lot of people tend to customize stuff.

My approach on one of my projects with graphql-yoga for example:

  • resolver functions were separated by functionality into subfolders but then imported in the /src/resolvers/ folder
  • graphql-yoga server instance in server.js in /server/
  • prisma content inside a /database/ folder instead of a /prisma/ folder

I try to make clear that each developer might think different in this πŸ˜„

Anmerkung 2019-04-05 140406

robinduerhager avatar Apr 05 '19 12:04 robinduerhager