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

graphile-export optimization: inline objects in fields() #424

Open
benjie opened this issue Jul 25, 2023 · 0 comments
Open

graphile-export optimization: inline objects in fields() #424

benjie opened this issue Jul 25, 2023 · 0 comments
Labels
💅 enhancement New feature or request

Comments

@benjie
Copy link
Member

benjie commented Jul 25, 2023

Currently Graphile Export attempts to make your code as efficient as possible via hoisting - anything that can be hoisted to the top will be. We should selectively un-hoist some of these things for legibility, especially where the hoisting confers no benefit.

One example is the GraphQLObjectTypeSpec.fields() callback. It will only be called once, so there's no need to hoist. i.e.

const SimilarTable1_col2_extensions = Object.assign(Object.create(null), {
  grafast: {
    plan($record) {
      return $record.get("col2");
    }
  }
});

export const SimilarTable1 = new GraphQLObjectType({
  name: "SimilarTable1",
  fields() {
    return {
      col2: {
        type: GraphQLInt,
        extensions: SimilarTable1_col2_extensions
      },
    };
  }
});

should become:

export const SimilarTable1 = new GraphQLObjectType({
  name: "SimilarTable1",
  fields() {
    return {
      col2: {
        type: GraphQLInt,
        extensions: Object.assign(Object.create(null), {
		  grafast: {
		    plan($record) {
		      return $record.get("col2");
		    }
		  }
		})
      },
    };
  }
});

We should also consider selectively downgrading Object.assign(Object.create(null), { ... }) to just { ... } where it's safe to do so. Maybe via a configuration flag ("dangerouslyReadable" 😉 )

@benjie benjie added the 💅 enhancement New feature or request label Jul 25, 2023
@benjie benjie added this to the V5 post launch milestone Jul 25, 2023
@benjie benjie added this to V5.0.0 Oct 4, 2023
@github-project-automation github-project-automation bot moved this to 🌳 Triage in V5.0.0 Oct 4, 2023
@benjie benjie removed this from V5.0.0 Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💅 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant