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

Contextual control of auto select depth #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dustymugs
Copy link

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
Copy link
Member

barbieri commented May 4, 2022

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
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.

2 participants