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

Make sub-directories work in import-dir #788

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

peterp
Copy link
Contributor

@peterp peterp commented Jul 2, 2020

This replaces the importAll.macro; you use it like this:

import services from 'src/services/**/*.{js,ts}'

services will be an object that contains all the imports of all the matched files in the directory, it's the equivalent of running:

let services = {}
import * as services_a from '../__fixtures__/a'
services.a = services_a
import * as services_b from '../__fixtures__/b'
services.b = services_b
import * as services_c_sdl from '../__fixtures__/c.sdl'
services.c_sdl = services_c_sdl
import * as services_nested_d from '../__fixtures__/nested/d'
services.nested_d = services_nested_d

/cc @noire-munich

@peterp peterp changed the title Make sub-directories work in import-dir. Make sub-directories work in import-dir Jul 2, 2020
@peterp peterp added this to the next release milestone Jul 2, 2020
@peterp peterp merged commit 9826c06 into main Jul 2, 2020
@noire-munich
Copy link
Collaborator

Ouuh yeah \o/ that's neat!
Thanks for the ping 😋

@jtoar
Copy link
Contributor

jtoar commented Jul 2, 2020

@peterp There needs to be a corresponding PR in https://github.com/redwoodjs/create-redwood-app right? A change to graphql.js:

import {
  createGraphQLHandler,
  makeMergedSchema,
  makeServices,
} from '@redwoodjs/api'
- import importAll from '@redwoodjs/api/importAll.macro'
+ import schemas from 'src/graphql/**/*.{js,ts}'
+ import services from 'src/services/**/*.{js,ts}'

import { db } from 'src/lib/db'

- const schemas = importAll('api', 'graphql')
- const services = importAll('api', 'services')

export const handler = createGraphQLHandler({
  schema: makeMergedSchema({
    schemas,
    services: makeServices({ services }),
  }),
  db,
})

@ericxjohnston
Copy link

@peterp @jtoar @thedavidprice The new import syntax which replaces the importAll.macro is good but it breaks the regex pattern match in the CLI generate auth command that handles adding the getCurrentUser import.

#830

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

Successfully merging this pull request may close these issues.

None yet

4 participants