Skip to content

Contextual control of auto select depth - #203

Closed
dustymugs wants to merge 1 commit into
profusion:masterfrom
dustymugs:BetterControlOfDepth
Closed

dustymugs wants to merge 1 commit into
profusion:masterfrom
dustymugs:BetterControlOfDepth

Conversation

@dustymugs

Copy link
Copy Markdown

This is purely a hack so as to contextually control DEFAULT_AUTO_SELECT_DEPTH as the default value of 2 may not be sufficient when sending the request and merging the response into the Operation object.

Example schema:

type Query {
        ...
	findProducts(input: ProductSearchInput): ProductSearchResults!
       ...
}

type ProductSearchResults {
	results: [ProductSearchResult!]!
	more: Boolean!
	nextLimit: Int!
	nextOffset: Int!
}

type ProductSearchResult {
	product: Product!
	instances: [Instance]!
}

type Product {
	id: ID!
	internalName: String!
	displayName: String
	description: String
	license: String
	reference: Json
	dataSteward: Json
	tags: [Tag!]!
	releases: [Release]!
}

type Instance {
	id: ID!
	productId: ID!
	productName: String!
	effectiveDateRange: DateRange
	ignoreTimezone: Boolean
	tags: [Tag!]
	reference: Json
	extent: GeoJson
	assets: [Asset!]!
	parents: [Instance!]
}

And a basic consumption...

op = Operation
op.find_products(input=...).__fields__()

results = op + endpoint.query(op)

With the default depth of 2, Product.tags and Product.releases (amongst other fields) are not included in the merged results.

With this PR, I can safely do the following and get Product.tags and Product.releases in the results

with select_depth(3):
  op = Operation
  op.find_products(input=...).__fields__()
  
  results = op + endpoint.query(op)

Obviously, a cleaner approach would be lovely (e.g. Operation(Query, max_select_depth=10) but this is the dirty solution to achieve my needs

@barbieri

barbieri commented May 4, 2022

Copy link
Copy Markdown
Member

hi @dustymugs, why don't you simply pass the argument to the functions?

Other than that, I highly recommend to NOT use auto-selection since it goes against the GraphQL principles. It will bring you lots of data, it will make your code more subject to breakages and so on.

Note this is a pure "dev only" thing I added to help quick hacks... I regret adding it when I see some "misuses" :-P

@barbieri barbieri self-assigned this May 4, 2022
@wallawonka

Copy link
Copy Markdown

@dustymugs did you get the chance to see the branch conflicts that must be resolved?

@barbieri

Copy link
Copy Markdown
Member

cleaning up, feel free to reopen considering the comments above if any.

@barbieri barbieri closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants